/**
 *  Created by zy on 2016/6/7.
 *  此 ui-main.js 作为整个完整性管理系统前端简单 ui 控制存在
 *  目前作用于 管体缺陷、设备管理、腐蚀控制、模块
 *  document.ready 内是页面简单动态样式的控制
 *  而整个项目前端通用控件也封装在此文件内,采用 jquery 插件模式
 */


$(document).ready(function () {

    /**
     * 设置输入框聚焦边框颜色为黑色
     */
    /*$('.zy-i-input').bind('focus blur', function () {
     var $this_input = $(this);
     var $parent = $this_input.parent('div.zy-input-inner');
     if ($parent.hasClass('zy-input-disabled')) {
     $this_input.attr('disabled', 'disabled');
     } else {
     $parent.toggleClass('active');
     }
     });*/

    /**
     * select2 配置
     */
    var $select2 = $('select.zy-select2');
    if ($select2.length > 0) {
        $.fn.select2.defaults.set('minimumResultsForSearch', 'Infinity');
        $.fn.select2.defaults.set('width', '100%');
        $.fn.select2.defaults.set('allowClear', true);
        $.fn.select2.defaults.set('placeholder', '请选择');
        $select2.select2();
    }

    /**
     * datetimepicker 配置
     */
    var $input_date = $('input.zy-i-input-date');
    if ($input_date.length > 0) {
        $.datetimepicker.setLocale('zh');
        $input_date.datetimepicker({
            timepicker: false,
            format: 'Y-m-d',
            scrollInput: false
        });
    }

    /**
     * 设置左侧菜单栏高度 - 重要
     */
    var $menu_bar = $('#JQ_sidebar_box');
    if ($menu_bar.length > 0) {
        $menu_bar.css({
            height: document.body.clientHeight - 112 - 80
        });
    }

    /**
     * 为 charts-box 计算宽高
     */
    var setChartWidth = function () {
        var $box = $('div.zy-charts-box');
        if ($box.length > 0) {
            $box.each(function () {
                var $this = $(this);
                var box_w = $this.width(), box_h = $this.height();
                var $head = $this.find('div.zy-charts-head');
                var $body = $this.find('div.zy-charts-body');
                var $inner = $this.find('div.zy-charts-inner');
                if ($body.length > 0) {
                    var sub = $body.attr('data-subwidth');
                    if ($head.length > 0) {
                        var head_h = $head.height();
                        box_h = box_h - head_h;
                    }
                    if ($inner.length > 0) {
                        box_w = box_w - 15 * 2;
                        box_h = box_h - 15 * 2;
                    }
                    if (sub) {
                        box_w = box_w - parseInt(sub);
                    }
                    $body.width(box_w).height(box_h);
                }
                var empty = $body.attr('data-empty');
                if (empty) {
                    //$body.empty().html('<img src="' + empty + '">');
                    $body.empty();
                }
            });
        }
    }();


    /**
     * 当charts-body数据为空时
     * 调用此clear事件填充临时图片
     */
    var setChartEmpty = function () {
        var $box = $('div.zy-charts-body');
        $box.on('clear', function () {
            var $this = $(this);
            var empty = $this.attr('data-empty');
            if (!empty) {
                empty = DyyBase.root_path + '/static/img/chart_no_data.png';
            }
            empty = '<img src="' + empty + '">';
            //$this.empty().html(empty);
            $this.empty();
        });
        // 此绑定事件用来显示完整性分析图表的 x,y tag
        $box.on('playTag', function (e, d) {
            var $this = $(this);
            var $ytag = $this.parents('div.zy-table').find('h3.zy-charts-top-tag');
            var $xtag = $this.parent('div.zy-charts-box').parent('div.l').siblings('div.r').find('div.zy-charts-bottom-tag');
            if (d === 'true') {
                if ($ytag.length > 0) {
                    $ytag.removeClass('hidden');
                }
                if ($xtag.length > 0) {
                    $xtag.removeClass('hidden');
                }
            } else if (d === 'false') {
                if ($ytag.length > 0) {
                    $ytag.addClass('hidden');
                }
                if ($xtag.length > 0) {
                    $xtag.addClass('hidden');
                }
            }
        })
    }();


    /**
     * 收起头部筛选表单
     */
    //var $pick = $('i.zy-meta-pick-icon');
    var $pick = $('div.xyf-toggle-form-div');
    if ($pick.length > 0) {
        $pick.click(function (event) {
            var $line = $('div.zy-pick-line');
            if ($line.length > 0) {
                $line.slideToggle('fast');
                $pick.toggleClass('active');
            }
            event.stopPropagation();
            return false;
        });
        $pick.off('pick').on('pick', function (event) {
            var $line = $('div.zy-pick-line');
            if ($line.length > 0) {
                $line.slideToggle('fast');
                $pick.toggleClass('active');
            }
            event.stopPropagation();
            return false;
        });
    }

    /**
     * 复选框
     */
    var $check = $('div.zy-checkbox-group');
    if ($check.length > 0) {
        var $c = $check.find('i.zy-checkbox');
        $c.click(function () {
            var $this = $(this);
            if (!($this.hasClass('disabled'))) {
                $this.toggleClass('active');
                $this.trigger('change');
            }
        });
    }

    /**
     * 单选框
     */
    var $radio = $('div.zy-radio-group');
    if ($radio.length > 0) {
        var $r = $radio.find('i.zy-radio-icon');
        $r.click(function () {
            var $this = $(this);
            if (!($this.hasClass('disabled'))) {
                $this.parent('label').parent('div').find('i.zy-radio-icon').removeClass('active');
                $this.addClass('active');
                $this.trigger('change');
            }
        });
    }

    /**
     * 记录为空时收起按钮事件
     */
    var $zy_table = $('div.zy-table');
    if ($zy_table.length > 0) {
        $zy_table.on('click', 'button.zy-pick-empty', function () {
            var $this = $(this);
            $this.parents('tr.zy-dy-empty').hide();
            $this.parents('table.zy-datatable').find('i').removeClass('active');
        })
    }


    /**
     * 为导出pdf外框设置高宽
     */
});


/**
 * checkbox3 为DataTable扩展一个checkbox头列
 * 调用形式: JQ.checkbox3()
 * 基本功能: 需要头列有checkbox的数据表格
 * 使用情景: 批量操作的数据表格
 */
/**
 * checkboxScroll 为DataTable在设置滚动模式下的扩展一个checkbox头列
 * 基本功能: 当表格滚动时
 * 使用情景: 批量操作的数据表格
 */
;(function ($) {
    $.fn.extend({
        checkbox3: function () {
            var self = this;

            self.on('click', 'i.zy-checkbox-all', function () {
                var $this = $(this);
                var $chk = self.find('i.zy-checkbox');
                var len = 0;
                var tag = $this.attr('data-chk');
                if ($chk.length > 0) {
                    if (tag == 'false') {
                        $chk.each(function (i) {
                            i++;
                            var $this_chk = $(this);
                            if (!($this_chk.hasClass('disabled'))) {
                                $this_chk.addClass('active');
                                len = i;
                            }
                        });
                        $this.data('total', len).data('count', len).attr('data-chk', 'true').addClass('active');
                    } else if (tag == 'true') {
                        $chk.removeClass('active');
                        $this.data('total', len).data('count', 0).attr('data-chk', 'false').removeClass('active');
                    }
                }
            });
            self.on('click', 'i.zy-checkbox', function () {
                var $all = self.find('i.zy-checkbox-all');
                var $chk = self.find('i.zy-checkbox');
                var len = $chk.length;
                if (len > 0) {
                    if (!($all.data('total')) && !($all.data('count'))) {
                        $all.data('total', len);
                        $all.data('count', 0);
                    }
                }
                var $this = $(this);
                if (!($this.hasClass('disabled'))) {
                    $this.toggleClass('active');
                }
                if ($this.hasClass('active')) {
                    var n = parseInt($all.data('count'));
                    n += 1;
                    $all.data('count', n);
                } else {
                    var m = parseInt($all.data('count'));
                    m -= 1;
                    $all.data('count', m);
                }
                if ($all.data('total') == $all.data('count')) {
                    $all.attr('data-chk', 'true').addClass('active');
                } else {
                    $all.attr('data-chk', 'false').removeClass('active');
                }
            });
            self.on('clear', 'i.zy-checkbox-all', function () {
                var $this = $(this);
                $this.data('total', 0).data('count', 0).attr('data-chk', 'false').removeClass('active');
            });
            return self;
        },

        checkboxScroll: function () {
            var self = this;
            $("#JQ_check_all").click(function () {
                var $this = $(this);
                var $chk = self.find('i.zy-checkbox');
                var len = $chk.length;
                var tag = $this.attr('data-chk');
                if (len > 0) {
                    if (tag == 'false') {
                        $chk.addClass('active');
                        $this.data('total', len).data('count', len).attr('data-chk', 'true').addClass('active');
                    } else if (tag == 'true') {
                        $chk.removeClass('active');
                        $this.data('total', len).data('count', 0).attr('data-chk', 'false').removeClass('active');
                    }
                }
            });
            self.on('click', 'i.zy-checkbox', function () {
                var $all = $("#JQ_check_all");
                var $chk = self.find('i.zy-checkbox');
                var len = $chk.length;
                if (len > 0) {
                    if (!($all.data('total')) && !($all.data('count'))) {
                        $all.data('total', len);
                        $all.data('count', 0);
                    }
                }
                var $this = $(this);
                $this.toggleClass('active');
                if ($this.hasClass('active')) {
                    var n = parseInt($all.data('count'));
                    n += 1;
                    $all.data('count', n);
                } else {
                    var m = parseInt($all.data('count'));
                    m -= 1;
                    $all.data('count', m);
                }
                if ($all.data('total') == $all.data('count')) {
                    $all.attr('data-chk', 'true').addClass('active');
                } else {
                    $all.attr('data-chk', 'false').removeClass('active');
                }
            });
            return self;
        }
    });
})(jQuery);

/**
 * xyf write 2016-12-02
 * 基础设置-角色设置-授权管理选框方法
 * checkNewScroll 为授权信息列表多选
 * toggleList多级的收起展开
 * addColor多级的颜色
 * 使用情景: 需验证form
 */
;(function ($) {
    $.fn.extend({
        checkNewScroll: function () {
            var self = this;

            $("#JQ_authorize_check_all").click(function () {
                var $this = $(this);
                var $chk = self.find('i.xyf-checkbox');
                var len = $chk.length;
                var tag = $this.attr('data-chk');
                if (len > 0) {
                    if (tag == 'false') {
                        $chk.addClass('active');
                        $this.attr('data-chk', 'true').addClass('active');
                    } else if (tag == 'true') {
                        $chk.removeClass('active').removeClass('half');
                        $this.attr('data-chk', 'false').removeClass('active').removeClass('half');
                    }
                }
            });

            self.on('click', 'i.xyf-checkbox', function () {
                var $this = $(this);
                var otherType = self.find('i.xyf-checkbox');  //所有的选择元素
                var selfType = $this.attr('data-type');

                if ($this.hasClass('active')) {
                    $this.removeClass('active').removeClass('half');
                    var upTrueArr = [];
                    if (otherType.length > 1) {
                        otherType.each(function () {
                            var oneVal = $(this).attr('data-type');  //每个i的type
                            //判断是否本身元素的子层
                            if (oneVal.length > selfType.length && oneVal.indexOf(selfType) > -1) {
                                $(this).removeClass('active');
                            }
                            //上级元素
                            if (oneVal.length < selfType.length && selfType.indexOf(oneVal) > -1) {
                                upTrueArr.push(oneVal);
                            }
                        });
                    }
                    parentState(upTrueArr);
                } else {
                    $this.addClass('active').removeClass('half');
                    var upTypeArr = [];
                    if (otherType.length > 1) {
                        otherType.each(function () {
                            var oneVal = $(this).attr('data-type');  //每个i的type
                            //判断是否本身元素的子层
                            if (oneVal.length > selfType.length && oneVal.indexOf(selfType) > -1) {
                                $(this).addClass('active').removeClass('half');
                            }
                            //上级元素
                            if (oneVal.length < selfType.length && selfType.indexOf(oneVal) > -1) {
                                upTypeArr.push(oneVal);
                            }
                        });
                    }

                    parentState(upTypeArr);
                }
                function parentState(types) {
                    var upArr = types.reverse();
                    for (var y = 0; y < upArr.length; y++) {
                        var typeArr = '';
                        var oneVal = upArr[y];
                        otherType.each(function () {
                            var twoVal = $(this).attr('data-type');
                            var twoIsCheck = '';
                            if (twoVal.length > oneVal.length && twoVal.indexOf(oneVal) > -1) {
                                twoIsCheck = $(this).hasClass('active').toString();
                                typeArr += twoIsCheck;
                            }
                        });
                        if (typeArr.indexOf('false') < 0) {
                            self.find('i[data-type=' + oneVal + ']').addClass('active').removeClass('half');
                        } else if (typeArr.indexOf('true') < 0) {
                            self.find('i[data-type=' + oneVal + ']').removeClass('active').removeClass('half');
                        } else {
                            self.find('i[data-type=' + oneVal + ']').removeClass('active').addClass('half');
                        }
                    }
                }

                //判断是否全选
                var $all = $("#JQ_authorize_check_all");
                var $chk = self.find('i.xyf-checkbox');
                var allType = '';
                var allIsCheck = '';
                $chk.each(function () {
                    allIsCheck = $(this).hasClass('active').toString();
                    allType += allIsCheck;
                });
                if (allType.indexOf('false') < 0) {
                    $all.attr('data-chk', 'true').addClass('active').removeClass('half');
                } else if (allType.indexOf('true') < 0) {
                    $all.attr('data-chk', 'false').removeClass('active').removeClass('half');
                } else {
                    $all.attr('data-chk', 'false').removeClass('active').addClass('half');
                }
            });

            //第五级收缩
            self.on('click', 'i.xyf-five', function () {
                var $this = $(this);
                var curType = $this.attr('data-type');
                var isTo = $this.hasClass('active');
                if (!($this.hasClass('none'))) {
                    toggleNode(isTo, '5', curType);
                    if (isTo == true) {
                        $this.removeClass('active');
                    } else {
                        $this.addClass('active');
                    }
                }
            });

            //第四级
            self.on('click', 'i.xyf-four', function () {
                var $this = $(this);
                var curType = $this.attr('data-type');
                var isTo = $this.hasClass('active');
                if (!($this.hasClass('none'))) {
                    toggleNode(isTo, '4', curType);
                    if (isTo == true) {
                        $this.removeClass('active');
                    } else {
                        $this.addClass('active');
                    }
                }
            });

            //第三级
            self.on('click', 'i.xyf-three', function () {
                var $this = $(this);
                var curType = $this.attr('data-type');
                var isTo = $this.hasClass('active');
                if (!($this.hasClass('none'))) {
                    toggleNode(isTo, '3', curType);
                    if (isTo == true) {
                        $this.removeClass('active');
                    } else {
                        $this.addClass('active');
                    }
                }
            });

            //第二级
            self.on('click', 'i.xyf-two', function () {
                var $this = $(this);
                var curType = $this.attr('data-type');
                var isTo = $this.hasClass('active');
                if (!($this.hasClass('none'))) {
                    toggleNode(isTo, '2', curType);
                    if (isTo == true) {
                        $this.removeClass('active');
                    } else {
                        $this.addClass('active');
                    }
                }
            });

            //第一级
            self.on('click', 'i.xyf-one', function () {
                var $this = $(this);
                var curType = $this.attr('data-type');
                var isTo = $this.hasClass('active');
                if (!($this.hasClass('none'))) {
                    toggleNode(isTo, '1', curType);
                    if (isTo == true) {
                        $this.removeClass('active');
                    } else {
                        $this.addClass('active');
                    }
                }
            });

            //第零级
            self.on('click', 'i.xyf-zero', function () {
                var $this = $(this);
                var isTo = $this.hasClass('active');
                if (!($this.hasClass('none'))) {
                    toggleNode(isTo, '0');
                    if (isTo == true) {
                        $this.removeClass('active');
                    } else {
                        $this.addClass('active');
                    }
                }
            });

            function toggleNode(bool, level, val) {
                var one = self.find('i.xyf-one');
                var two = self.find('i.xyf-two');
                var three = self.find('i.xyf-three');
                var four = self.find('i.xyf-four');
                var five = self.find('i.xyf-five');
                var six = self.find('i.xyf-six');
                if (level == '0') {
                    if (bool) {
                        one.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            $this.removeClass('xyf-zero-c');
                            $tr.show();
                        });

                        two.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            $this.removeClass('xyf-zero-c');
                            if (!($this.hasClass('xyf-zero-one'))) {
                                $tr.show();
                            }
                        });
                        three.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            $this.removeClass('xyf-zero-c');
                            if (!($this.hasClass('xyf-zero-one')) && !($this.hasClass('xyf-zero-two'))) {
                                $tr.show();
                            }
                        });
                        four.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            $this.removeClass('xyf-zero-c');
                            if (!($this.hasClass('xyf-zero-one')) && !($this.hasClass('xyf-zero-two')) && !($this.hasClass('xyf-zero-three'))) {
                                $tr.show();
                            }
                        });
                        five.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            $this.removeClass('xyf-zero-c');
                            if (!($this.hasClass('xyf-zero-one')) && !($this.hasClass('xyf-zero-two')) && !($this.hasClass('xyf-zero-three')) && !($this.hasClass('xyf-zero-four'))) {
                                $tr.show();
                            }
                        });
                        six.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            $this.removeClass('xyf-zero-c');
                            if (!($this.hasClass('xyf-zero-one')) && !($this.hasClass('xyf-zero-two')) && !($this.hasClass('xyf-zero-three')) && !($this.hasClass('xyf-zero-four')) && !($this.hasClass('xyf-zero-five'))) {
                                $tr.show();
                            }
                        });
                    } else {
                        one.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            $this.addClass('xyf-zero-c');
                            $tr.hide();
                        });
                        two.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            $this.addClass('xyf-zero-c');
                            if (!($this.hasClass('xyf-zero-one'))) {
                                $tr.hide();
                            }
                        });
                        three.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            $this.addClass('xyf-zero-c');
                            if (!($this.hasClass('xyf-zero-one')) && !($this.hasClass('xyf-zero-two'))) {
                                $tr.hide();
                            }
                        });
                        four.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            $this.addClass('xyf-zero-c');
                            if (!($this.hasClass('xyf-zero-one')) && !($this.hasClass('xyf-zero-two')) && !($this.hasClass('xyf-zero-three'))) {
                                $tr.hide();
                            }
                        });
                        five.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            $this.addClass('xyf-zero-c');
                            if (!($this.hasClass('xyf-zero-one')) && !($this.hasClass('xyf-zero-two')) && !($this.hasClass('xyf-zero-three')) && !($this.hasClass('xyf-zero-four'))) {
                                $tr.hide();
                            }
                        });
                        six.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            $this.addClass('xyf-zero-c');
                            if (!($this.hasClass('xyf-zero-one')) && !($this.hasClass('xyf-zero-two')) && !($this.hasClass('xyf-zero-three')) && !($this.hasClass('xyf-zero-four')) && !($this.hasClass('xyf-zero-five'))) {
                                $tr.hide();
                            }
                        });
                    }
                } else if (level == '1') {
                    if (bool) {
                        two.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.removeClass('xyf-zero-one');
                                $tr.show();
                            }
                        });
                        three.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.removeClass('xyf-zero-one');
                                if (!($this.hasClass('xyf-zero-two'))) {
                                    $tr.show();
                                }
                            }
                        });
                        four.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.removeClass('xyf-zero-one');
                                if (!($this.hasClass('xyf-zero-two')) && !($this.hasClass('xyf-zero-three'))) {
                                    $tr.show();
                                }
                            }
                        });
                        five.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.removeClass('xyf-zero-one');
                                if (!($this.hasClass('xyf-zero-two')) && !($this.hasClass('xyf-zero-three')) && !($this.hasClass('xyf-zero-four'))) {
                                    $tr.show();
                                }
                            }
                        });
                        six.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.removeClass('xyf-zero-one');
                                if (!($this.hasClass('xyf-zero-two')) && !($this.hasClass('xyf-zero-three')) && !($this.hasClass('xyf-zero-four')) && !($this.hasClass('xyf-zero-five'))) {
                                    $tr.show();
                                }
                            }
                        });
                    } else {
                        two.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.addClass('xyf-zero-one');
                                $tr.hide();
                            }
                        });
                        three.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.addClass('xyf-zero-one');
                                if (!($this.hasClass('xyf-zero-two'))) {
                                    $tr.hide();
                                }
                            }
                        });
                        four.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.addClass('xyf-zero-one');
                                if (!($this.hasClass('xyf-zero-two')) && !($this.hasClass('xyf-zero-three'))) {
                                    $tr.hide();
                                }
                            }
                        });
                        five.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.addClass('xyf-zero-one');
                                if (!($this.hasClass('xyf-zero-three')) && !($this.hasClass('xyf-zero-four'))) {
                                    $tr.hide();
                                }
                            }
                        });
                        six.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.addClass('xyf-zero-one');
                                if (!($this.hasClass('xyf-zero-three')) && !($this.hasClass('xyf-zero-four')) && !($this.hasClass('xyf-zero-five'))) {
                                    $tr.hide();
                                }

                            }
                        });
                    }
                } else if (level == '2') {
                    if (bool) {
                        three.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.removeClass('xyf-zero-two');
                                $tr.show();
                            }
                        });
                        four.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.removeClass('xyf-zero-two');
                                if (!($this.hasClass('xyf-zero-three'))) {
                                    $tr.show();
                                }
                            }
                        });
                        five.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.removeClass('xyf-zero-two');
                                if (!($this.hasClass('xyf-zero-three')) && !($this.hasClass('xyf-zero-four'))) {
                                    $tr.show();
                                }
                            }
                        });
                        six.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.removeClass('xyf-zero-two');
                                if (!($this.hasClass('xyf-zero-three')) && !($this.hasClass('xyf-zero-four')) && !($this.hasClass('xyf-zero-five'))) {
                                    $tr.show();
                                }
                            }
                        });
                    } else {
                        three.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.addClass('xyf-zero-two');
                                $tr.hide();
                            }
                        });
                        four.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.addClass('xyf-zero-two');
                                if (!($this.hasClass('xyf-zero-three'))) {
                                    $tr.hide();
                                }
                            }
                        });
                        five.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.addClass('xyf-zero-two');
                                if (!($this.hasClass('xyf-zero-three')) && !($this.hasClass('xyf-zero-four'))) {
                                    $tr.hide();
                                }
                            }
                        });
                        six.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.addClass('xyf-zero-two');
                                if (!($this.hasClass('xyf-zero-three')) && !($this.hasClass('xyf-zero-four')) && !($this.hasClass('xyf-zero-five'))) {
                                    $tr.hide();
                                }

                            }
                        });
                    }
                } else if (level == '3') {
                    if (bool) {
                        four.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.removeClass('xyf-zero-three');
                                $tr.show();
                            }
                        });
                        five.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.removeClass('xyf-zero-three');
                                if (!($this.hasClass('xyf-zero-four'))) {
                                    $tr.show();
                                }
                            }
                        });
                        six.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.removeClass('xyf-zero-three');
                                if (!($this.hasClass('xyf-zero-four')) && !($this.hasClass('xyf-zero-five'))) {
                                    $tr.show();
                                }
                            }
                        });
                    } else {
                        four.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.addClass('xyf-zero-three');
                                $tr.hide();
                            }
                        });
                        five.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.addClass('xyf-zero-three');
                                if (!($this.hasClass('xyf-zero-four'))) {
                                    $tr.hide();
                                }
                            }
                        });
                        six.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.addClass('xyf-zero-three');
                                if (!($this.hasClass('xyf-zero-four')) && !($this.hasClass('xyf-zero-five'))) {
                                    $tr.hide();
                                }

                            }
                        });
                    }
                } else if (level == '4') {
                    if (bool) {
                        five.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.removeClass('xyf-zero-four');
                                $tr.show();
                            }
                        });
                        six.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.removeClass('xyf-zero-four');
                                if (!($this.hasClass('xyf-zero-five'))) {
                                    $tr.show();
                                }
                            }
                        });
                    } else {
                        five.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.addClass('xyf-zero-four');
                                $tr.hide();
                            }
                        });
                        six.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.addClass('xyf-zero-four');
                                if (!($this.hasClass('xyf-zero-five'))) {
                                    $tr.hide();
                                }

                            }
                        });
                    }
                } else if (level == '5') {
                    if (bool) {
                        six.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.removeClass('xyf-zero-five');
                                $tr.show();
                            }
                        });
                    } else {
                        six.each(function () {
                            var $this = $(this);
                            var $tr = $this.parent('td').parent('tr');
                            var oneVal = $this.attr('data-type');  //每个i的type
                            //子层元素
                            if (oneVal.length > val.length && oneVal.indexOf(val) > -1) {
                                $this.addClass('xyf-zero-five');
                                $tr.hide();
                            }
                        });
                    }
                }
            }

            return self;

        }
    });
})(jQuery);
;(function ($) {
    $.fn.extend({
        addColor: function () {
            var self = $(this);
            /** 菜单背景色 start **/
            //一级菜单背景颜色
            var oneColor = self.find('i.xyf-one-checked');
            if (oneColor.length > 0) {
                oneColor.each(function () {
                    var $tr = $(this).parent('td').parent('tr');
                    $tr.addClass('xyf-one-backColor');
                });
            }
            //二级菜单背景颜色
            var twoColor = self.find('i.xyf-two-checked');
            twoColor.each(function () {
                var $tr = $(this).parent('td').parent('tr');
                $tr.addClass('xyf-two-backColor');
            });
            //三级菜单背景颜色
            var threeColor = self.find('i.xyf-three-checked');
            threeColor.each(function () {
                var $tr = $(this).parent('td').parent('tr');
                $tr.addClass('xyf-three-backColor');
            });
            //四级菜单背景颜色
            var fourColor = self.find('i.xyf-four-checked');
            fourColor.each(function () {
                var $tr = $(this).parent('td').parent('tr');
                $tr.addClass('xyf-four-backColor');
            });
            /** 菜单背景色 end **/


            /** 默认选中的状态 start **/
            var defaultCheck = self.find('i.xyf-state1');
            defaultCheck.each(function () {
                var $this = $(this);
                var curType = $this.attr('data-type');
                var childTypes = getChild(curType).checkTypes;
                if (childTypes.indexOf('false') < 0) {
                    $this.addClass('active').removeClass('half');
                } else if (childTypes.indexOf('true') < 0) {
                    $this.removeClass('half').removeClass('active');
                } else {
                    $this.addClass('half').removeClass('active');
                }
            });
            //判断全局
            var $all = $("#JQ_authorize_check_all");
            var allType = getChild().allCheckTypes;
            if (allType.indexOf('false') < 0) {
                $all.attr('data-chk', 'true').addClass('active').removeClass('half');
            } else if (allType.indexOf('true') < 0) {
                $all.attr('data-chk', 'false').removeClass('active').removeClass('half');
            } else {
                $all.attr('data-chk', 'false').removeClass('active').addClass('half');
            }
            /** 默认选中的状态 end **/


            /** 是否还有下一级菜单 start **/
            var cur = self.find('i.haveData');
            cur.each(function () {
                var $this = $(this);
                var curType = $this.attr('data-type');
                var childNodes = getChild(curType, 'b').childNodes;
                if (childNodes.length == 0) {
                    $this.addClass('none');
                }
            });
            /** 是否还有下一级菜单 start **/

            function getChild(curType, type) {
                var obj = {checkTypes: '', allCheckTypes: '', childNodes: []};
                //所有的选择元素
                var otherType;
                if (type == 'b') {
                    otherType = self.find('i.haveData');
                } else {
                    otherType = self.find('i.xyf-checkbox');
                }
                if (curType) {
                    if (otherType.length > 1) {
                        otherType.each(function () {
                            var oneVal = $(this).attr('data-type');  //每个i的type
                            //获取所有子层元素
                            if (oneVal.length > curType.length && oneVal.indexOf(curType) > -1) {
                                obj.checkTypes += $(this).hasClass('xyf-state1').toString();
                                obj.childNodes.push(oneVal);
                            }
                        });
                    }
                } else {
                    otherType.each(function () {
                        obj.allCheckTypes += $(this).hasClass('xyf-state1').toString();
                    });
                }
                return obj;
            }

            return self;
        }
    });
})(jQuery);


/**
 * dragLine 为完整性分析画拖拽线
 * 可以左右拖动改变大小
 */
;(function ($) {
    function C(element, options) {
        this.element = element;
        this.defaults = {
            width: 0,
            height: 0,
            top: 0,
            left: 0,
            scale: null
        };
        this.settings = $.extend({}, this.defaults, options);
    }

    C.prototype = {
        clear: function () {
            var self = this;
            self.element.find('div.zy-charts-drag-div').remove();
            $(document).off('mousemove').off('mouseup');
            return self;
        },
        init: function () {
            var self = this;

            // first clear
            self.clear();

            var w = self.settings.width ? self.settings.width : self.element.width();
            var h = self.settings.height ? self.settings.height : self.element.height();

            var s_offset = self.element.offset();
            var s_offset_left = s_offset.left + w;

            var $drag_box = $('<div class="zy-charts-drag-div"></div>');
            var $drag_left = $('<div class="zy-charts-drag-left"><em class="zy-charts-drag-left-dot l-1"></em><em class="zy-charts-drag-left-dot l-2"></em></div>');
            var $drag_middle = $('<div class="zy-charts-drag-middle"></div>');
            var $drag_right = $('<div class="zy-charts-drag-right"><em class="zy-charts-drag-left-dot r-1"></em><em class="zy-charts-drag-left-dot r-2"></em></div>');

            $drag_left.height(h);
            $drag_middle.height(h);
            $drag_right.height(h);

            // drag ------------------------------------------------------ start
            function getCss(tag, pos) {
                return parseFloat((tag.css(pos)).replace('px', ''));
            }

            $drag_box.data('left', (w - 30)).data('width', 30).css({
                'left': (self.settings.left ? self.settings.left : (w - 30)),
                'top': (self.settings.top ? self.settings.top : (59)),
            });

            $drag_left.off('mousedown').on('mousedown', function (event) {
                $drag_left.data('drag', true).data('x', parseFloat(event.clientX));
                $drag_box.data('offsetLeft', $drag_box.offset().left);
            });
            $drag_middle.off('mousedown').on('mousedown', function (event) {
                $drag_box.data('drag', true).data('x', parseFloat(event.clientX));
            });
            $drag_middle.off('dblclick').on('dblclick', function (event) {
                $drag_left.data('drag', false);
                $drag_box.data('drag', false);
                $drag_right.data('drag', false);

                $drag_middle.stop().animate({
                    'width': 10
                }, 'fast', 'swing');

                $drag_box.stop().animate({
                    'left': (w - 30),
                    'width': 30
                }, 'fast', 'swing', function () {
                    $drag_box.data('width', getCss($drag_box, 'width')).data('left', getCss($drag_box, 'left'));
                });
            });
            $drag_right.off('mousedown').on('mousedown', function (event) {
                $drag_right.data('drag', true).data('x', parseFloat(event.clientX));
            });


            $(document).off('mousemove').on('mousemove', function (event) {
                var left_drag = $drag_left.data('drag');
                var box_drag = $drag_box.data('drag');
                var right_drag = $drag_right.data('drag');

                var x = event.clientX;
                var offset_left = parseFloat($drag_box.offset().left);
                var dis_box_width = 0;

                if (left_drag) {
                    if (x > s_offset.left + 40 && x < s_offset_left - 30) {
                        var offset_pos_left = parseFloat($drag_box.data('offsetLeft'));
                        var dis_offset_pos = parseFloat(offset_pos_left - x);
                        var data_box_width = parseFloat($drag_box.data('width'));
                        data_box_width += dis_offset_pos;
                        if (data_box_width > 29) {
                            $drag_box.width(data_box_width).css({
                                'left': (parseFloat($drag_box.data('left')) - dis_offset_pos)
                            });
                            $drag_middle.width(data_box_width - 20);
                            console.log(self.settings.scale.invert(dis_offset_pos));
                        }
                    }
                }

                if (box_drag) {
                    if (x > s_offset.left && x < s_offset_left) {
                        var dis = x - parseFloat($drag_box.data('x'));
                        var dis_x = parseFloat($drag_box.data('left')) + dis;
                        if(dis_x > 40){
                            $drag_box.css({
                                'left': dis_x
                            });
                        }
                    }
                }

                if (right_drag) {
                    if (x < s_offset_left) {
                        dis_box_width = Math.abs(x - offset_left);
                        if (dis_box_width > 29 && x > offset_left) {
                            $drag_box.width(dis_box_width);
                            $drag_middle.width(dis_box_width - 20);
                        }
                    }
                }
            });

            $(document).off('mouseup').on('mouseup', function () {
                $drag_left.data('drag', false);
                $drag_box.data('drag', false).data('width', getCss($drag_box, 'width')).data('left', getCss($drag_box, 'left'));
                $drag_right.data('drag', false);
            });
            // drag ------------------------------------------------------ end

            $drag_box.height(h);
            $drag_box.append($drag_left).append($drag_middle).append($drag_right);

            self.element.append($drag_box);
            $drag_box.fadeIn('fast');

            return self;
        }
    };

    $.fn.dragLine = function (options) {
        var line = new C(this, options);
        return line.init();
    };

})(jQuery);


/**
 * verify 为form扩展一个验证方法
 * 调用形式: JQ.verify()
 * 基本功能: 将验证form内符合规则的控件值
 * 使用情景: 需验证form
 */
;(function ($) {
    $.fn.extend({
        // form 验证
        verify: function () {
            // 错误集合
            var fail = [];
            // 验证状态
            var mode = true;

            // 所用到的正则表达式
            var int = /^\-?[1-9][0-9]*$/;                                                               // (正/负整数)
            var plus = /^[1-9][0-9]*$/;                                                                 // (正整数)
            var minus = /^-[1-9][0-9]*$/;                                                               // (负整数)
            var email = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;      // (email)
            var mobile = /^1[3|4|5|8|7][0-9]\d{4,8}$/;                                                  // (手机)
            var tel = /^([0-9]{3,4}-)?[0-9]{7,8}$/;                                                     // (座机)
            var telMobile = /^((0\d{2}-\d{8})|(0\d{3}-\d{7})|(1[3|4|5|8|7][0-9]\d{4,8}))$/;             // 联系电话：座机或手机
            // (日期 - 包含闰年闰月 Y-m-d)
            var date = /(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)/;

            // 方法 - 验证(正/负整数)
            function fint(t, v, f) {
                if (int.test(v)) {
                    if (f.range) {
                        if ((v < f.range[0]) || (v > f.range[1])) {
                            fail.push({target: t, error: f.title + '须在' + f.range[0] + '~' + f.range[1] + '范围内!'});
                        }
                    }
                } else {
                    fail.push({target: t, error: f.title + '须为整数!'});
                }
            }

            // 方法 - 验证(正整数)
            function fplus(t, v, f) {
                if (plus.test(v)) {
                    if (f.range) {
                        if ((v < f.range[0]) || (v > f.range[1])) {
                            fail.push({target: t, error: f.title + '须在' + f.range[0] + '~' + f.range[1] + '范围内!'});
                        }
                    }
                } else {
                    fail.push({target: t, error: f.title + '须为正整数!'});
                }
            }

            // 方法 - 验证(负整数)
            function fminus(t, v, f) {
                if (minus.test(v)) {
                    if (f.range) {
                        if ((v < f.range[0]) || (v > f.range[1])) {
                            fail.push({target: t, error: f.title + '须在' + f.range[0] + '~' + f.range[1] + '范围内!'});
                        }
                    }
                } else {
                    fail.push({target: t, error: f.title + '须为负整数!'});
                }
            }

            // 方法 - 验证(数字)
            function fnumber(t, v, f) {
                if (isNaN(v)) {
                    fail.push({target: t, error: f.title + '需为数字!'});
                } else {
                    if (v.indexOf('.') > -1) {
                        var v1 = v.split('.');
                        if (v1.length === 2) {
                            if (v1[1] && v1[0] != '00') {
                                if (f.range && f.round) {
                                    if ((v < f.range[0]) || (v > f.range[1])) {
                                        fail.push({target: t, error: f.title + '须在' + f.range[0] + '~' + f.range[1] + '范围内!'});
                                    } else {
                                        if (f.round && v1[1].length > f.round) {
                                            if (v1[1].length > 1) {
                                                fail.push({target: t, error: f.title + '保留' + f.round + '位小数即可!'});
                                            }
                                        }
                                    }
                                } else if (f.range && !(f.round)) {
                                    if ((v < f.range[0]) || (v > f.range[1])) {
                                        fail.push({target: t, error: f.title + '须在' + f.range[0] + '~' + f.range[1] + '范围内!'});
                                    }
                                } else if (!(f.range) && f.round) {
                                    if (f.round && v1[1].length != f.round) {
                                        if (v1[1].length > f.round) {
                                            fail.push({target: t, error: f.title + '保留' + f.round + '位小数即可!'});
                                        }
                                    }
                                }
                            } else {
                                fail.push({target: t, error: f.title + '需为数字!'});
                            }
                        } else {
                            fail.push({target: t, error: f.title + '需为数字!'});
                        }
                    } else {
                        if (f.range) {
                            if ((v < f.range[0]) || (v > f.range[1])) {
                                fail.push({target: t, error: f.title + '须在' + f.range[0] + '~' + f.range[1] + '范围内!'});
                            }
                        }
                    }
                }
            }

            // 方法 - 验证(email)
            function femail(t, v, f) {
                if (!(email.test(v))) {
                    fail.push({target: t, error: f.title + '格式不正确!'});
                }
            }

            // 方法 - 验证(手机)
            function fmobile(t, v, f) {
                if (!(mobile.test(v))) {
                    fail.push({target: t, error: f.title + '格式不正确!'});
                }
            }

            // 方法 - 验证(座机)
            function ftel(t, v, f) {
                if (!(tel.test(v))) {
                    fail.push({target: t, error: f.title + '格式不正确!'});
                }
            }

            // 方法 - 验证(联系电话)
            function ftelMobile(t, v, f) {
                if (!(telMobile.test(v))) {
                    fail.push({target: t, error: f.title + '不正确，座机格式为（区号-号码）!'});
                }
            }

            // 方法 - 验证(日期)
            function fdate(t, v, f) {
                if (f.format === 'Y-m-d') {
                    if (!(date.test(v))) {
                        fail.push({target: t, error: f.title + '格式不正确!'});
                    }
                }
            }

            // 进入验证
            function validate(t) {
                var v = t.val() ? t.val() : t.data('value');
                var f = t.attr('data-verify');
                if (f) {
                    f = eval('(' + f + ')');
                } else {
                    f = {};
                }
                if (f.required === true) {
                    v = $.trim(v);
                    if (v) {
                        switch (f.type) {
                            case 'int':
                                fint(t, v, f);
                                break;
                            case 'plus':
                                fplus(t, v, f);
                                break;
                            case 'minus':
                                fminus(t, v, f);
                                break;
                            case 'number':
                                fnumber(t, v, f);
                                break;
                            case 'email':
                                femail(t, v, f);
                                break;
                            case 'mobile':
                                fmobile(t, v, f);
                                break;
                            case 'tel':
                                ftel(t, v, f);
                                break;
                            case 'telMobile':
                                ftelMobile(t, v, f);
                                break;
                            case 'date':
                                fdate(t, v, f);
                                break;
                            default:
                                break;
                        }
                    } else {
                        fail.push({target: t, error: f.title + '不能为空!', scroll: f.scroll});
                    }
                } else {
                    v = $.trim(v);
                    if (v) {
                        switch (f.type) {
                            case 'int':
                                fint(t, v, f);
                                break;
                            case 'plus':
                                fplus(t, v, f);
                                break;
                            case 'minus':
                                fminus(t, v, f);
                                break;
                            case 'number':
                                fnumber(t, v, f);
                                break;
                            case 'email':
                                femail(t, v, f);
                                break;
                            case 'mobile':
                                fmobile(t, v, f);
                                break;
                            case 'tel':
                                ftel(t, v, f);
                                break;
                            case 'telMobile':
                                ftelMobile(t, v, f);
                                break;
                            case 'date':
                                fdate(t, v, f);
                                break;
                            default:
                                break;
                        }
                    }
                }
            }

            // 为元素绑定验证
            var $v = this.find('.zy-verify');
            if ($v.length > 0) {
                $v.each(function () {
                    var $this = $(this);
                    if (!($this.hasClass('non'))) {
                        validate($this);
                    }
                });
            }

            // 存在错误
            if (fail.length > 0) {
                mode = false;
                for (var i = 0, len = fail.length; i < len; i++) {
                    fail[i]['target'].TIP({
                        content: fail[i]['error'],
                        scroll: fail[i]['scroll']
                    });
                }
            }

            return mode;
        }
    });
})(jQuery);


/**
 * loadImg 是一个点击查看大图的方法
 * 调用形式JQ.loadImg
 * data为一个数组参数，是图片的路劲组成的数组
 * src是字符串参数，是点击的图片的路劲，若不是从点击图片触发此函数，src可以不传或为空值
 * 使用场景清管模块的查看图片部分，如果以后有类似的也可以调用
 */
;(function ($) {
    $.fn.extend({
        loadImg: function (data, srcId, func) {
            var self = this;
            self.empty();
            var w_h = $(window).height();
            var w_w = $(window).width();
            var img_btn_oY = (w_h - 150) / 2;

            var $mask = $('<div class="xyf-img-boost"></div>');
            $mask.css({
                'height': w_h,
                'width': w_w
            });
            self.append($mask);

            //留白
            //var $close_div = $('<div class="xyf-close-img-div"></div>');
            //$mask.append($close_div);
            //$close_div.click(function(){
            //    $mask.hide();
            //    if(func && func instanceof Function){
            //        func();
            //    }
            //});
            var $close_icon = $('<div class="xyf-close-img-icon"></div>');
            $mask.append($close_icon);
            $close_icon.click(function () {
                $mask.hide();
                if (func && func instanceof Function) {
                    func();
                }
            });

            //前翻
            var $img_prev = $('<div class="xyf-img-prev-btn xyf-action-title" title="上一张"></div>');
            $img_prev.css({
                'top': img_btn_oY,
                'left': 80
            });
            $mask.append($img_prev);

            //后翻
            var $img_next = $('<div class="xyf-img-next-btn xyf-action-title" title="下一张"></div>');
            $img_next.css({
                'top': img_btn_oY,
                'right': 80
            });
            $mask.append($img_next);


            //图片初始化
            var $img_div = $('<div class="xyf-img-box"><img id=""   class="xyf-img-src"/></div>');
            $mask.append($img_div);
            $img_div.css({
                'width': w_w - 360,
                'height': w_h - 100
            });

            var $img_content = $('img.xyf-img-src');
            if ($img_content) {
                if (data.length > 1) {
                    if (srcId != '' && srcId != undefined) {
                        var src_index;
                        for (var a = 0; a < data.length; a++) {
                            if (data[a].id == srcId) {
                                src_index = a;
                            }
                        }
                        if (src_index == 0) {
                            $img_prev.hide();
                            $img_next.show();
                        } else if (src_index == data.length - 1) {
                            $img_prev.show();
                            $img_next.hide();
                        } else {
                            $img_prev.show();
                            $img_next.show();
                        }
                        $img_content.attr('id', data[src_index].id);
                        $img_content.attr('src', data[src_index].path);
                    } else {
                        $img_prev.hide();
                        $img_next.show();
                        $img_content.attr('id', data[0].id);
                        $img_content.attr('src', data[0].path);
                    }
                } else if (data.length == 1) {
                    $img_prev.hide();
                    $img_next.hide();
                    $img_content.attr('id', data[0].id);
                    $img_content.attr('src', data[0].path);
                }
                $img_content.hide();
            }

            //判断当前是第几张图片

            //图片加载完成确定其宽度位置
            $("img").on("load", function () {
                var img_w = $(this).width();
                var img_h = $(this).height();
                var divScale = (w_w - 360) / (w_h - 100);
                var imgScale = img_w / img_h;
                if (imgScale < divScale) {
                    $img_content.css({
                        'height': w_h - 100
                    });
                } else if (imgScale == divScale) {
                    $img_content.css({
                        'width': w_w - 360,
                        'height': w_h - 100
                    });
                } else if (imgScale > divScale) {
                    var d_w = w_w - 360;
                    var d_h = w_h - 100;
                    var top_h = (d_h - d_w * img_h / img_w) / 2;
                    $img_content.css({
                        'width': w_w - 360,
                        'marginTop': top_h
                    });
                }
                $img_content.show();
            });

            //查看前一张图片
            $img_prev.click(function () {
                var imgSrc = $img_content.attr('id');
                var imgIndex;
                for (var b = 0; b < data.length; b++) {
                    if (data[b].id == imgSrc) {
                        imgIndex = b;
                    }
                }
                if (imgIndex >= 0) {
                    $img_content.attr('src', data[imgIndex - 1].path);
                    $img_content.attr('id', data[imgIndex - 1].id);
                    if (imgIndex == 1) {
                        $img_prev.hide();
                    }
                }
                $img_next.show();
            });

            //查看后一张图片
            $img_next.click(function () {
                var imgSrc = $img_content.attr('id');
                var imgIndex;
                for (var b = 0; b < data.length; b++) {
                    if (data[b].id == imgSrc) {
                        imgIndex = b;
                    }
                }
                if (imgIndex + 1 < data.length) {
                    $img_content.attr('src', data[imgIndex + 1].path);
                    $img_content.attr('id', data[imgIndex + 1].id);
                    if (imgIndex + 2 == data.length) {
                        $img_next.hide();
                    }
                }
                $img_prev.show();
            })
        }
    });
})(jQuery);


/**
 * loadSmallImage 是页面上的一个小图的插件
 * 调用形式JQ.loadSmallImage,并传入数组参数；
 * 使用场景清管模块的查看图片部分，如果以后有类似的也可以调用
 */
;(function ($) {
    $.fn.extend({
        loadSmallImage: function (data, func1, func2, exportPdf) {
            var self = this;
            self.empty();
            var len = data.length;
            var page = Math.ceil(len / 6);

            //没有图片是显示的div
            var $null = $('<div class="xyf-small-img-null"></div>');
            self.append($null);

            //图片展示外层
            var $mask = $('<div class="xyf-small-image-display"></div>');
            self.append($mask);
            var $this_mask = self.find($mask);

            //上一页按钮
            var $prev = $('<div class="xyf-small-image-prev"></div>');
            $this_mask.append($prev);

            //下一页按钮
            var $next = $('<div class="xyf-small-image-next"></div>');
            $this_mask.append($next);

            //添加图片
            var $img_list = $('<ul class="xyf-small-image-list"></ul>');
            $img_list.css('width', 6 * 66 * page);
            $this_mask.append($img_list);
            if (exportPdf) {
                for (var k = 0; k < len; k++) {
                    var $img_liP = $('<li><img crossorigin="anonymous" id="' + data[k].id + '" src="' + data[k].path + '" onload="storeImage(this)"/></li>');
                    $img_list.append($img_liP);
                }
            } else {
                for (var i = 0; i < len; i++) {
                    var $img_li = $('<li><img id="' + data[i].id + '" src="' + data[i].path + '"/></li>');
                    $img_list.append($img_li);
                }
            }


            //判断图片张数
            var $next_btn = self.find($next); //下一张
            var $prev_btn = self.find($prev); //上一张
            var $img_null = self.find('div.xyf-small-img-null'); //图片为空时显示

            if (Object.prototype.toString.call(data) === '[object Array]' && data.length !== 0) {
                if (len > 6) {
                    $next_btn.show();
                    $prev_btn.hide();
                } else if (len > 0 && len < 7) {
                    $next_btn.hide();
                    $prev_btn.hide();
                }
                $img_null.hide();
            } else {
                $next_btn.hide();
                $prev_btn.hide();
                $img_null.show();
                $img_list.hide();
            }

            //没有图片显示时的点击事件
            $img_null.click(function () {
                $('.main-inner').MSG({'content': '没有图片数据！'})
            });

            //左右翻页显示图片
            var j = 0;
            if (page > 1) {
                $next_btn.click(function (e) {
                    if (j >= page - 1) {
                        return;
                    }
                    j++;
                    if (j == page - 1) {
                        $next_btn.hide();
                    }
                    $prev_btn.show();
                    moveMile(j);
                });
                $prev_btn.click(function (e) {
                    if (j <= 0) {
                        return;
                    }
                    j--;
                    if (j == 0) {
                        $prev_btn.hide();
                    }
                    $next_btn.show();
                    moveMile(j);
                })
            }
            function moveMile(j) {
                $this_mask.find($img_list).animate({'left': -396 * j}, 1000);
            }

            //点击图片查看大图
            self.find('img').click(function () {
                var $this = $(this);
                var srcId = $this.attr('id');
                if (func1 && func1 instanceof Function) {
                    func1();
                }
                $('#JQ_img_div').loadImg(data, srcId, func2);
            })
        },
        loadAeImage: function (data) {
            var self = this;
            var len = data.length;
            var page = Math.ceil(len / 6);

            //没有图片是显示的div
            var $null = $('<div class="xyf-ae-img-null"></div>');
            self.append($null);

            //图片展示外层
            var $mask = $('<div class="xyf-ae-image-display"></div>');
            self.append($mask);
            var $this_mask = self.find($mask);

            //上一页按钮
            var $prev = $('<div class="xyf-ae-image-prev"></div>');
            $this_mask.append($prev);

            //下一页按钮
            var $next = $('<div class="xyf-ae-image-next"></div>');
            $this_mask.append($next);

            //添加图片
            var $img_list = $('<ul class="xyf-ae-image-list"></ul>');
            $img_list.css('width', 924 * page);
            $this_mask.append($img_list);
            for (var i = 0; i < len; i++) {
                var $img_li = $('<li><img id="' + data[i].id + '" src="' + data[i].path + '"></li>');
                $img_list.append($img_li);
            }

            //判断图片张数
            var $next_btn = self.find($next); //下一张
            var $prev_btn = self.find($prev); //上一张
            var $img_null = self.find('div.xyf-ae-img-null'); //图片为空时显示
            if (len > 6) {
                $next_btn.show();
                $prev_btn.hide();
                $img_null.hide();
            } else if (len > 0 && len < 7) {
                $next_btn.hide();
                $prev_btn.hide();
                $img_null.hide();
            } else {
                $next_btn.hide();
                $prev_btn.hide();
                $img_null.show();
            }

            //没有图片显示时的点击事件
            $img_null.click(function () {
                $('.main-inner').MSG({'content': '没有图片数据！'})
            });

            //左右翻页显示图片
            var j = 0;
            if (page > 1) {
                $next_btn.click(function (e) {
                    if (j >= page - 1) {
                        return;
                    }
                    j++;
                    if (j == page - 1) {
                        $next_btn.hide();
                    }
                    $prev_btn.show();
                    moveMile(j);
                });
                $prev_btn.click(function (e) {
                    if (j <= 0) {
                        return;
                    }
                    j--;
                    if (j == 0) {
                        $prev_btn.hide();
                    }
                    $next_btn.show();
                    moveMile(j);
                })
            }
            function moveMile(j) {
                $this_mask.find($img_list).animate({'left': -924 * j}, 500);
            }

            //点击图片查看大图
            self.find('img').click(function () {
                var $this = $(this);
                var srcId = $this.attr('id');
                $('#JQ_img_div').loadImg(data, srcId);
            })
        }
    });
})(jQuery);


/**
 * reset 为form扩展一个重置方法
 * 调用形式: JQ.reset()
 * 基本功能: 将form内控件值置空 (注:) 清空自定义控件值
 * 使用情景: 清空form值
 */
;(function ($) {
    $.fn.extend({
        reset: function () {
            var self = this;
            // 重置 普通表单
            var $reset = $('<input type="reset" style="display:none">');
            self.append($reset);
            $reset.trigger('click');
            // 重置 select3
            var $select3 = self.find('blockquote.bk-select');
            if ($select3.length > 0) {
                $select3.trigger('reset');
            }
            // 重置 动态table
            var $table = self.find('table.zy-datatable');
            if ($table.length > 0) {
                $table.trigger('reset');
            }
        }
    });
})(jQuery);


/**
 * UPW 上传检测报告弹出框(附件)
 * 调用形式: JQ.UPW()
 * 基本功能: 上传
 * 使用情景: (非内检上传检测报告)
 */
;(function ($) {
    function W(element, options) {
        this.element = element;
        this.defaults = {
            'width': 400,
            'height': 300,
            'yesBtn': '',
            'yesBtnAct': '',
            'closeBtn': '',
            'closeBtnAct': '',
            'fileType': 'defectInspectionReport',                       // 文件分类
            'businessId': '0',                                          // 对应业务ID
            'suffix': {title: 'Doc files', extensions: 'doc,pdf,docx'}   // 上传文件类型(后缀名)
        };
        this.settings = $.extend({}, this.defaults, options);
    }

    W.prototype = {
        mask: function () {
            var w_h = $(window).height();
            var w_w = $(window).width();
            var $mask = $('<div class="zy-msg-mask active"></div>');
            $mask.css({
                'height': w_h,
                'width': w_w
            });
            if ($(document.body).find('div.zy-msg-mask').length == 0) {
                $(document.body).append($mask);
                $mask.fadeIn('fast');
            }
        },
        clear: function () {
            $(document.body).find('div.zy-msg-mask').remove();
            $(document.body).find('div.zy-upload-box').remove();
        },
        init: function () {
            var self = this;

            // 外框
            var w_w = $(window).width();
            var w_h = $(window).height();
            var $upload_box = $('<div class="zy-upload-box"></div>');
            $upload_box.css({
                'height': self.settings.height,
                'width': self.settings.width,
                'top': (w_h / 2) - (self.settings.height / 2),
                'left': (w_w / 2) - (self.settings.width / 2)
            });

            // 关闭按钮
            var $close_p = $('<p class="zy-msg-close-p"></p>');
            var $close_btn = $('<span class="zy-msg-close-span" title="关闭"></span>');
            $close_p.click(function () {
                if (self.settings.closeBtnAct instanceof Function) {
                    self.settings.closeBtnAct(self.clear);
                } else {
                    self.clear();
                }
            });
            $close_p.append($close_btn);
            $upload_box.append($close_p);

            // 图标 - p
            var $icon_p = $('<p class="zy-upload-icon-p"><span class="zy-upload-icon-span"></span></p>');
            $upload_box.append($icon_p);

            // 上传进度条
            var $process_bar = $('<div class="zy-upload-process-div"><p class="zy-upload-process"><span id="JQ_upload_file_name" class="zy-upload-file-name">等待上传...</span><span class="zy-upload-file-bar" title="上传进度"><span id="JQ_upload_file_bar"></span></span></p></div>');
            $upload_box.append($process_bar);

            // 上传按钮外框
            var $upload_div = $('<div class="zy-upload-select-div"></div>');

            // 上传button
            var $upload_button = $('<button class="zy-upload-btn-select">选择文件</button>');
            var dom_btn = $upload_button.get(0);

            // 追加
            $upload_div.append($upload_button);
            $upload_box.append($upload_div);

            // 执行遮罩
            self.mask();
            $(document.body).append($upload_box);

            // 追加完成后
            // 实例化一个plupload上传对象
            var uploader = new plupload.Uploader({
                browse_button: dom_btn,
                multi_selection: false,
                url: DyyBase.url_upload_file(),
                filters: {
                    mime_types: [
                        self.settings.suffix
                    ]
                },
                multipart_params: {
                    businessId: self.settings.businessId,
                    type: self.settings.fileType,
                    onlyOne: 'true'
                },
                flash_swf_url: DyyBase.root_path + '/static/js/plugin/plupload/Moxie.swf',
                silverlight_xap_url: DyyBase.root_path + '/static/js/plugin/plupload/Moxie.xap',
                init: {
                    BeforeUpload: function (u, f) {
                    },
                    UploadProgress: function (u, f) {
                        var w = 200 * (f.percent / 100);
                        $process_bar.find('#JQ_upload_file_bar').css({
                            'width': w
                        });
                    },
                    FileUploaded: function (u, f, info) {
                        $icon_p.find('span.zy-upload-icon-span').addClass('success');
                        self.element.data('info', info);
                        self.element.data('fileinfo', f);
                    },
                    UploadComplete: function (u, f) {
                    },
                    Error: function (u, f) {
                        // 移除列队中的文件
                        function RF(u, f) {
                            if (f.length > 0) {
                                for (var j = 0, len = f.length; j < len; j++) {
                                    u.removeFile(f[j]);
                                }
                            }
                        }

                        if (f.code == -601) {
                            RF(u, f);
                            var msg = f.file.name + '文件格式不正确！<br>请上传 (' + self.settings.suffix.extensions + ') 格式文件！';
                            $upload_div.MSG({
                                type: 'error',
                                content: msg
                            });
                            // 还原
                            $icon_p.find('span.zy-upload-icon-span').removeClass('success');
                            $process_bar.find('#JQ_upload_file_name').text('等待上传...');
                            $process_bar.find('#JQ_upload_file_bar').css({
                                'width': 0
                            });
                        }
                    },
                    FilesAdded: function (u, f) {
                        $process_bar.find('#JQ_upload_file_name').text(f[0].name).prop('title', f[0].name);
                        uploader.start();
                    }
                }
            });

            // 初始化
            uploader.init();

            return self;
        }
    };

    $.fn.UPW = function (options) {
        var _wnd = new W(this, options);
        return _wnd.init();
    };
})(jQuery);


/**
 * TIP 提示悬浮框
 * 调用形式: JQ.TIP()
 * 基本功能: 在控件上方悬浮提示
 * 使用情景: 验证提示
 */
;(function ($) {
    var T = function (element, options) {
        this.element = element;
        this.defaults = {
            'timer': 1000,
            'height': 27,
            'width': 150,
            'content': '温馨提示',
            'background-color': '#000000',
            'scroll': true,
            'zindex': ''
        };
        this.settings = $.extend({}, this.defaults, options);
    };

    T.prototype = {
        init: function () {
            var self = this;
            var pos_l = self.element.position().left;
            var pos_t = self.element.position().top;
            //var pos_h = self.element.parent().height();

            var tip_out = $('<div class="tip-out"><span class="tip-arrow"></span></div>');
            var tip_body = $('<div class="tip-body"></div>');
            tip_body.html(self.settings.content);
            tip_out.append(tip_body);
            tip_out.css({
                'left': pos_l,
                'top': -38,
                'z-index': self.settings.zindex ? self.settings.zindex : 111
            }).show();

            //$(document.body).append(tip_out);
            self.element.after(tip_out);

            if (self.settings.scroll) {
                if(!window.isTipScroll){
                    $(window).scrollTop(pos_t - self.settings.height - 10 - 90);
                    window.isTipScroll = true;
                }
            }

            function hide() {
                tip_out.stop().fadeOut('slow', function () {
                    tip_out.remove();
                    window.isTipScroll = null;
                });
            }

            setTimeout(hide, self.settings.timer);

            return self;
        }
    };

    $.fn.TIP = function (options) {
        var tip = new T(this, options);
        return tip.init();
    };
})(jQuery);


/**
 * MSG 通用弹出框
 * 调用形式: JQ.MSG()
 * 基本功能: alert & confirm
 * 使用情景: 操作反馈
 */
;(function ($) {
    var G = function (options) {
        this.defaults = {
            'type': 'alert', // 当前4种类型: alert,error,success,confirm
            'tag': 'ok',
            'width': 400,
            'height': 300,
            'iconClass': '',
            'title': '温馨提示',
            'content': '操作信息',
            'yesBtnTxt': '知道了',
            'noBtnTxt': '取消',
            'yesBtnAct': '',
            'noBtnAct': '',
            'closeBtnAct': '',
            'closeBtn': '',
            'msgBox': '',
            'goBackStep': -1,
            'goToUrl': '',
            'closeBtnExist': true,
            'contentTitle': '',
            'contentAddon': '',
            'contentMust': ''
        };
        this.settings = $.extend({}, this.defaults, options);
    };
    G.prototype = {
        mask: function () {
            var w_h = $(window).height();
            var w_w = $(window).width();
            var $mask = $('<div class="zy-msg-mask"></div>');
            $mask.css({
                'height': w_h,
                'width': w_w
            });
            if ($(document.body).find('div.zy-msg-mask').length === 0) {
                $(document.body).append($mask);
                $mask.fadeIn('fast');
            }
            return this;
        },
        clear: function () {
            var $mask = $(document.body).find('div.zy-msg-mask');
            if (!($mask.hasClass('active'))) {
                $mask.remove();
            }
            $(document.body).find('div.zy-msg-outer').remove();
            return this;
        },
        open: function () {
            var self = this;
            var $outer = $(document.body).find('div.zy-msg-outer');
            var $p = $outer.find('p.zy-msg-content-p');
            var t_w = self.settings.width + 260;
            var t_h = self.settings.height + 180;
            var pos_l = $outer.position().left - 260 / 2;
            var pos_t = $outer.position().top - 180 / 2;
            $outer.stop().animate({
                'width': t_w,
                'height': t_h,
                'left': pos_l,
                'top': pos_t
            }, 'fast');
            $p.css({
                'height': 250,
                'overflow-y': 'scroll',
                'text-align': 'left',
                'line-height': '25px'
            }).html(self.settings.content);
            $outer.find('div.zy-msg-open-details').remove();
        },
        init: function () {
            var self = this;
            self.mask();

            var w_h = $(window).height();
            var w_w = $(window).width();
            var $outer = $('<div class="zy-msg-outer"></div>');
            $outer.css({
                'height': self.settings.height,
                'width': self.settings.width,
                'left': (w_w / 2) - (self.settings.width / 2),
                'top': (w_h / 2) - (self.settings.height / 2)
            }).show();

            // 右上角关闭按钮
            var $close_p = $('<p class="zy-msg-close-p"></p>');
            var $close_btn = $('<span class="zy-msg-close-span" title="关闭"></span>');
            if (self.settings.closeBtnExist) {
                $close_btn.off('click').click(function () {
                    if (self.settings.closeBtnAct instanceof Function) {
                        if (self.settings.goToUrl) {
                            self.settings.closeBtnAct(self.settings.goToUrl);
                        } else if (self.settings.goBackStep < -1) {
                            self.settings.closeBtnAct(self.settings.goBackStep);
                        } else {
                            self.clear();
                            self.settings.closeBtnAct();
                        }
                    } else {
                        self.clear();
                    }
                });
                $close_p.append($close_btn);
            }
            $outer.append($close_p);

            // 图标
            var $icon = $('<p class="zy-msg-icon-p"><i></i></p>');
            switch (self.settings.type) {
                case 'alert':
                    $icon.find('i').addClass('zy-msg-icon-alert');
                    $outer.append($icon);
                    break;
                case 'error':
                    $icon.find('i').addClass('zy-msg-icon-error');
                    $outer.append($icon);
                    break;
                case 'success':
                    $icon.find('i').addClass('zy-msg-icon-success');
                    $outer.append($icon);
                    break;
                default:
                    break;
            }

            // 标题
            var $title = $('<p class="zy-msg-title-p"></p>');
            $title.text(self.settings.title);
            $outer.append($title);

            // 信息
            var $content = $('<p class="zy-msg-content-p"></p>');
            if (self.settings.content) {
                var temp = '';
                var $open = $('<div class="zy-msg-open-details">展开详细...</div>');
                $open.click(function () {
                    self.open();
                });
                if (self.settings.contentTitle) {
                    if (self.settings.contentTitle.length > 18) {
                        temp = '<span title="' + self.settings.contentTitle + '">' + self.settings.contentTitle.substring(0, 18) + '...' + '</span>';
                    }
                    if (self.settings.contentAddon) {
                        temp += self.settings.contentAddon;
                    }
                    if (self.settings.contentMust) {
                        temp += self.settings.contentMust;
                    }
                    $content.html(temp).append($open);
                } else {
                    if (self.settings.content.length > 50) {
                        temp = self.settings.content.substring(0, 50) + '...';
                        $content.html(temp).append($open);
                    } else {
                        $content.html(self.settings.content);
                    }
                }
            } else {
                $content.html('server error!');
            }
            $outer.append($content);

            // 确认按钮
            var $btn_yes = $('<button type="button" class="zy-msg-button"></button>');
            $btn_yes.text(self.settings.yesBtnTxt);
            $btn_yes.off('click').click(function () {
                if (self.settings.yesBtnAct instanceof Function) {
                    if (self.settings.goToUrl) {
                        self.settings.yesBtnAct(self.settings.goToUrl);
                    } else if (self.settings.goBackStep < -1) {
                        self.settings.yesBtnAct(self.settings.goBackStep);
                    } else {
                        self.clear();
                        self.settings.yesBtnAct();
                    }
                } else {
                    self.clear();
                }
            });

            // 取消按钮
            var $btn_no = $('<button type="button" class="zy-msg-button"></button>');
            $btn_no.text(self.settings.noBtnTxt);
            $btn_no.off('click').click(function () {
                if (self.settings.noBtnAct instanceof Function) {
                    if (self.settings.goToUrl) {
                        self.settings.noBtnAct(self.settings.goToUrl);
                    } else if (self.settings.goBackStep < -1) {
                        self.settings.noBtnAct(self.settings.goBackStep);
                    } else {
                        self.clear();
                    }
                } else {
                    self.clear();
                }
            });

            // 选择模式
            var $btnp = $('<p class="zy-msg-btns-p"></p>');
            if (self.settings.type == 'confirm') {
                if (self.settings.tag == 'ok') {
                    $btn_yes.addClass('zy-msg-ok');
                } else if (self.settings.tag == 'no') {
                    $btn_yes.addClass('zy-msg-no');
                }
                $btnp.append($btn_yes);
                $btnp.append($btn_no);
            } else {
                $btnp.append($btn_yes);
            }
            $outer.append($btnp);

            if ($(document.body).find('div.zy-msg-outer').length == 0) {
                $(document.body).append($outer);
                $outer.fadeIn('fast');
            }
        }
    };

    $.fn.MSG = function (options) {
        var msg = new G(options);
        return msg.init();
    };
})(jQuery);


/**
 * WIND 通用新建 & 编辑弹出框
 * 调用形式: JQ.WIND()
 * 基本功能: create & edit
 * 使用情景: 新建 & 编辑
 */
;(function ($) {
    function X(options) {
        this.defaults = {
            width: 600,
            height: 400,
            title: '标题',                      // 标题
            actionBox: 'div.zy-action-box',     // 外盒子
            closeBtn: 'i.zy-action-close',      // 关闭按钮
            closeBtnAct: '',                    // 关闭函数
            yesBtn: 'JQ_action_yes_btn',        // 确认按钮
            noBtn: 'JQ_action_no_btn',          // 取消按钮
            yesBtnAct: '',                      // 确认函数
            noBtnAct: '',                       // 取消函数
            yesBtnTxt: '确认',                  // 确认按钮文本
            noBtnTxt: '取消',                   // 取消按钮文本
            resetForm: ''                       // 需要重置的表单-JQ对象
        };
        this.settings = $.extend({}, this.defaults, options);
    }

    X.prototype = {
        mask: function () {
            var w_h = $(window).height();
            var w_w = $(window).width();
            var $mask = $('<div class="zy-msg-mask active"></div>');
            $mask.css({
                'height': w_h,
                'width': w_w
            });
            if ($(document.body).find('div.zy-msg-mask').length == 0) {
                $(document.body).append($mask);
                $mask.fadeIn('fast');
            }
            return this;
        },
        clear: function () {
            $(document.body).find('div.zy-msg-mask').remove();
            $(document.body).find('div.zy-action-box').hide();
            //$(document.body).removeClass('zy-body-no-scroll');
            return this;
        },
        init: function () {
            var self = this;

            // disabled body scroll
            //$(document.body).addClass('zy-body-no-scroll');

            // action - box
            var w_h = ($(window).height()) / 2 - (self.settings.height / 2);
            var w_w = ($(window).width()) / 2 - (self.settings.width / 2);
            var $action_box;
            if (self.settings.actionBox) {
                $action_box = $(self.settings.actionBox);
                $action_box.css({
                    'width': self.settings.width,
                    'height': self.settings.height,
                    'left': w_w,
                    'top': w_h
                }).data('left', w_w).data('top', w_h);
            }

            // drag ------------------------------------------------------ start
            var $title_bar = $action_box.find('div.zy-action-title');

            function getCss(tag, pos) {
                return parseInt((tag.css(pos)).replace('px', ''));
            }

            $title_bar.off('mousedown').on('mousedown', function (event) {
                $action_box.data('drag', true).data('x', event.clientX).data('y', event.clientY);
            });
            $(document).off('mousemove').on('mousemove', function (event) {
                var drag = $action_box.data('drag');
                if (drag) {
                    var x = event.clientX - $action_box.data('x');
                    var y = event.clientY - $action_box.data('y');
                    var dis_x = $action_box.data('left') + x;
                    var dis_y = $action_box.data('top') + y;
                    $action_box.css({
                        'left': dis_x,
                        'top': dis_y
                    });
                }
            });
            $(document).off('mouseup').on('mouseup', function () {
                $action_box.data('left', getCss($action_box, 'left'));
                $action_box.data('top', getCss($action_box, 'top'));
                $action_box.data('drag', false);
            });
            // drag ------------------------------------------------------ end

            // title
            var $title_span = $action_box.find('span.zy-action-span');
            if (self.settings.title) {
                $title_span.text(self.settings.title);
            }

            // closeBtn
            if (self.settings.closeBtn) {
                self.settings.closeBtn = $(self.settings.closeBtn);
                self.settings.closeBtn.off('click').click(function () {
                    if(!(self.settings.closeBtn.attr('disabled'))){
                        if(self.settings.closeBtnAct instanceof Function){
                            self.settings.closeBtnAct(self.clear);
                        }else{
                            if(self.settings.resetForm){
                                self.settings.resetForm.reset();
                            }
                            self.clear();
                        }
                    }
                });
            }

            // yesBtn
            if (self.settings.yesBtn) {
                self.settings.yesBtn = $('#' + self.settings.yesBtn);
                self.settings.yesBtn.html(self.settings.yesBtnTxt).off('click').click(function () {
                    if (!(self.settings.yesBtn.attr('disabled'))) {
                        if (self.settings.yesBtnAct instanceof Function) {
                            self.settings.yesBtnAct(self.clear);
                        } else {
                            self.clear();
                        }
                    }
                });
            }

            // noBtn
            if (self.settings.noBtn) {
                self.settings.noBtn = $('#' + self.settings.noBtn);
                self.settings.noBtn.html(self.settings.noBtnTxt).off('click').click(function () {
                    if(!(self.settings.noBtn.attr('disabled'))){
                        if(self.settings.noBtnAct instanceof Function){
                            self.settings.noBtnAct(self.clear);
                        }else{
                            if(self.settings.resetForm){
                                self.settings.resetForm.reset();
                            }
                            self.clear();
                        }
                    }
                });
            }

            $action_box.show();
            self.mask();
            return self;
        }
    };
    $.fn.WIND = function (options) {
        var win = new X(options);
        return win.init();
    }
})(jQuery);


/**
 * EXPT 通用导出弹出框
 * 调用形式: JQ.EXPT()
 * 基本功能: 导出 excel,doc,pdf前
 * 传输名字
 * 注意：拷贝至WIND 扩展了表单提交功能
 */
;(function ($) {
    function E(options) {
        this.name = '';
        this.defaults = {
            width: 550,
            height: 290,
            title: '导出',                              // 标题
            actionBox: 'div.zy-export-box',             // 外盒子
            closeBtn: 'i.zy-action-close',              // 关闭按钮
            closeBtnAct: '',                            // 关闭函数
            yesBtn: 'button.export-button-yes',         // 确认按钮
            noBtn: 'button.export-button-no',           // 取消按钮
            yesBtnAct: '',                      // 确认函数
            noBtnAct: '',                       // 取消函数
            yesBtnTxt: '<i class="zy-setsave-icon"></i>确认',                  // 确认按钮文本
            noBtnTxt: '取消',                   // 取消按钮文本
            resetForm: '',                      // 需要重置的表单-JQ对象
            param: '',                          // 表单参数
            server: '/',                        // 导出api
            name: '',                           // 导出标题
            type: 'name',                       // 文件内标题 title or name
            drag: true                          // 是否启用拖拽
        };
        this.settings = $.extend({}, this.defaults, options);
    }

    E.prototype = {
        mask: function () {
            var w_h = $(window).height();
            var w_w = $(window).width();
            var $mask = $('<div class="zy-msg-mask active"></div>');
            $mask.css({
                'height': w_h,
                'width': w_w
            });
            if ($(document.body).find('div.zy-msg-mask').length === 0) {
                $(document.body).append($mask);
                $mask.fadeIn('fast');
            }
            return this;
        },
        clear: function () {
            $(document.body).find('div.zy-msg-mask').remove();
            $(document.body).find('div.zy-action-box').hide();
            return this;
        },
        init: function () {

            var self = this;

            // width - height
            var w_h = ($(window).height()) / 2 - (self.settings.height / 2);
            var w_w = ($(window).width()) / 2 - (self.settings.width / 2);

            // action - box
            var $action_box;
            if (self.settings.actionBox) {
                $action_box = $(self.settings.actionBox);
                $action_box.css({
                    'width': self.settings.width,
                    'height': self.settings.height,
                    'left': w_w,
                    'top': w_h
                }).data('left', w_w).data('top', w_h);
            }

            // input
            var $input_name = $action_box.find('input[name="export_name"]');
            if ($input_name.length > 0 && self.settings.name) {
                $input_name.val(self.settings.name);
            }

            // iframe
            var $iframe = $action_box.find('iframe[name="export_iframe"]');
            if ($iframe.length) {
                $iframe.get(0).onload = function () {
                    try {
                        var content = this.contentWindow.document.body.innerHTML;
                        if (content) {
                            content = $.parseJSON(content);
                            if (!content.bool) {
                                if (content.message === 'sessionStatusFalse') {
                                    $(this).MSG({
                                        type: 'error',
                                        content: content.result,
                                        yesBtnAct: DyyBase.goLogin,
                                        closeBtnAct: DyyBase.goLogin
                                    });
                                } else {
                                    $(this).MSG({
                                        type: 'error',
                                        content: content.result
                                    });
                                }
                            }
                        }
                    } catch (e) {
                        $(this).MSG({
                            type: 'error',
                            content: e.message
                        });
                    }
                };
            }

            // form
            var $form = $action_box.find('form[name="export_form"]');
            if ($form.length > 0) {
                var action = self.settings.server + '?AjaxMode=true&random=' + (Math.random()).toString();
                $form.empty().attr('action', action);

                var param = self.settings.param;
                if (param) {
                    if (param instanceof Function) {
                        param = param();
                    }
                }

                for (var k in param) {
                    var $hidden = $('<input type="hidden">');
                    $hidden.prop('name', k).val(param[k]);
                    $form.append($hidden);
                }
            }

            // drag ------------------------------------------------------ start
            if (self.settings.drag) {
                var $title_bar = $action_box.find('div.zy-action-title');

                function getCss(tag, pos) {
                    return parseInt((tag.css(pos)).replace('px', ''));
                }

                $title_bar.off('mousedown').on('mousedown', function (event) {
                    $action_box.data('drag', true).data('x', event.clientX).data('y', event.clientY);
                });
                $(document).off('mousemove').on('mousemove', function (event) {
                    var drag = $action_box.data('drag');
                    if (drag) {
                        var x = event.clientX - $action_box.data('x');
                        var y = event.clientY - $action_box.data('y');
                        var dis_x = $action_box.data('left') + x;
                        var dis_y = $action_box.data('top') + y;
                        $action_box.css({
                            'left': dis_x,
                            'top': dis_y
                        });
                    }
                });
                $(document).off('mouseup').on('mouseup', function () {
                    $action_box.data('left', getCss($action_box, 'left'));
                    $action_box.data('top', getCss($action_box, 'top'));
                    $action_box.data('drag', false);
                });
            }
            // drag ------------------------------------------------------ end

            // title
            var $title_span = $action_box.find('span.zy-action-span');
            if (self.settings.title) {
                $title_span.text(self.settings.title);
            }

            // closeBtn
            if (self.settings.closeBtn) {
                self.settings.closeBtn = $(self.settings.closeBtn);
                self.settings.closeBtn.off('click').click(function () {
                    if (self.settings.closeBtnAct instanceof Function) {
                        self.clear();
                        self.settings.closeBtnAct();
                    } else {
                        if (self.settings.resetForm) {
                            self.clear();
                            self.settings.resetForm.reset();
                        } else {
                            self.clear();
                        }
                    }
                });
            }

            // yesBtn
            if (self.settings.yesBtn) {
                self.settings.yesBtn = $(self.settings.yesBtn);
                self.settings.yesBtn.html(self.settings.yesBtnTxt).off('click').click(function () {
                    var mode = true;
                    var val = $.trim($input_name.val());
                    if (DyyBase.notEmpty(val)) {
                        if (val.length > 50) {
                            $input_name.TIP({
                                content: '导出名称不能超过50个字符!',
                                scroll: false
                            });
                            mode = false;
                        }
                    } else {
                        $input_name.TIP({
                            content: '导出名称不能为空!',
                            scroll: false
                        });
                        mode = false;
                    }
                    if (mode) {
                        if (self.settings.yesBtnAct instanceof Function) {
                            self.name = val;
                            self.settings.yesBtnAct(self.clear, self.name);
                        } else {
                            self.clear();
                            var $name = $('<input type="hidden">');
                            if (self.settings.type === 'title') {
                                $name.prop('name', 'fileTitle').val(val);
                            } else if (self.settings.type === 'name') {
                                $name.prop('name', 'fileName').val(val);
                            }
                            $form.append($name).submit();
                        }
                    }
                });
            }

            // noBtn
            if (self.settings.noBtn) {
                self.settings.noBtn = $(self.settings.noBtn);
                self.settings.noBtn.html(self.settings.noBtnTxt).off('click').click(function () {
                    if (self.settings.noBtnAct instanceof Function) {
                        self.settings.noBtnAct(self.clear);
                    } else {
                        if (self.settings.resetForm) {
                            self.clear();
                            self.settings.resetForm.reset();
                        } else {
                            self.clear();
                        }
                    }
                });
            }

            $action_box.show();
            self.mask();
            return self;
        }
    };
    $.fn.EXPT = function (options) {
        var expt = new E(options);
        return expt.init();
    }
})(jQuery);


/**
 * timePicker 时间选择
 * 调用形式: JQ.timePicker()
 * 基本功能: 滑动选择 00:00 - 12:00 范围内时间
 * 使用情景: 选择时钟位置
 */
;(function ($) {
    function T(element, options) {
        this.element = element;
        this.defaults = {
            width: 300,
            height: 300,
            title: '选择时间'
        };
        this.settings = $.extend({}, this.defaults, options);
    }

    T.prototype = {
        init: function () {
            var self = this;
            self.element.data('time', '00:00');
            var pos_l = self.element.offset().left, pos_t = self.element.offset().top;
            var height = self.element.height();

            var $outbox = $('<div class="zy-timer-picker"></div>');
            $outbox.css({
                'left': 0,
                'top': height
            });

            var $title = $('<div class="zy-timer-title"></div>');
            if (self.settings.title) {
                $title.text(self.settings.title);
            }
            $outbox.append($title);

            var $time_show = $('<div class="zy-timer-line"><span class="sp">时间</span><span><abbr class="zy-timer-show-h">00</abbr>:<abbr class="zy-timer-show-m">00</abbr></span></div>');
            var $time_show_h = $time_show.find('abbr.zy-timer-show-h');
            var $time_show_m = $time_show.find('abbr.zy-timer-show-m');
            $outbox.append($time_show);

            var $hour_line = $('<div class="zy-timer-line"><span class="sp">时</span><span class="zy-timer-slide"><div class="zy-timer-slide-bar"></div><div class="zy-timer-slide-btn"></div></span></div>');
            var $hour_btn = $hour_line.find('div.zy-timer-slide-btn');

            var $min_line = $('<div class="zy-timer-line"><span class="sp">分</span><span class="zy-timer-slide"><div class="zy-timer-slide-bar"></div><div class="zy-timer-slide-btn"></div></span></div>');
            var $min_bar = $min_line.find('div.zy-timer-slide-bar');
            var $min_btn = $min_line.find('div.zy-timer-slide-btn');

            function showTime(flag) {
                if (flag) {
                    $time_show_h.text('00');
                    $time_show_m.text('00');
                    self.element.data('time', '');
                    self.element.val('');
                    $min_btn.stop().animate({
                        'left': 0
                    });
                    $hour_btn.stop().animate({
                        'left': 0
                    });
                    $hour_btn.data('left', 0).data('top', 9);
                    $min_btn.data('left', 0).data('top', 9);
                    $min_btn.removeClass('disabled');
                    $min_bar.removeClass('disabled');
                } else {
                    var temp_hour = $time_show_h.text();
                    var temp_min = $time_show_m.text();
                    var temp_time = temp_hour + ':' + temp_min;
                    self.element.data('time', temp_time);
                    self.element.val(temp_time);
                }
            }

            /* --------- timer slide --------- */
            $hour_btn.data('left', 0).data('top', 9);
            $min_btn.data('left', 0).data('top', 9);
            function getCss(tag, pos) {
                return parseInt((tag.css(pos)).replace('px', ''));
            }

            $hour_btn.off('mousedown').on('mousedown', function (event) {
                $hour_btn.data('drag', true).data('x', event.clientX).data('y', event.clientY);
            });
            $min_btn.off('mousedown').on('mousedown', function (event) {
                $min_btn.data('drag', true).data('x', event.clientX).data('y', event.clientY);
            });
            $(document).off('mousemove').on('mousemove', function (event) {
                var drag_hour = $hour_btn.data('drag');
                var drag_min = $min_btn.data('drag');
                if (drag_hour) {
                    var x = event.clientX - $hour_btn.data('x');
                    var dis_x = $hour_btn.data('left') + x;
                    if (dis_x >= 0 && dis_x <= 156) {
                        var temp_x = dis_x / 1.56;
                        if (true) {
                            var time_h = parseInt(dis_x / 13);
                            time_h = time_h < 10 ? '0' + time_h.toString() : time_h.toString();
                            $time_show_h.text(time_h);
                            if (time_h == 12) {
                                $min_btn.stop().animate({
                                    'left': 0
                                });
                                $min_btn.addClass('disabled');
                                $min_bar.addClass('disabled');
                                $time_show_m.text('00');
                            } else {
                                $min_btn.removeClass('disabled');
                                $min_bar.removeClass('disabled');
                            }
                            showTime();
                        }
                        $hour_btn.css({
                            'left': temp_x + '%'
                        });
                    }
                }
                if (drag_min) {
                    if (!($min_btn.hasClass('disabled'))) {
                        var xx = event.clientX - $min_btn.data('x');
                        var dis_xx = $min_btn.data('left') + xx;
                        if (dis_xx >= 0 && dis_xx <= 156) {
                            var temp_xx = dis_xx / 1.56;
                            if (true) {
                                var time_m = parseInt(dis_xx / 2.6);
                                time_m = time_m < 10 ? '0' + time_m.toString() : time_m.toString();
                                ;
                                time_m = time_m > 59 ? '59' : time_m.toString();
                                $time_show_m.text(time_m);
                                showTime();
                            }
                            $min_btn.css({
                                'left': temp_xx + '%'
                            });
                        }
                    }
                }
            });
            $(document).off('mouseup').on('mouseup', function () {
                $hour_btn.data('left', getCss($hour_btn, 'left'));
                $hour_btn.data('top', getCss($hour_btn, 'top'));
                $hour_btn.data('drag', false);

                $min_btn.data('left', getCss($min_btn, 'left'));
                $min_btn.data('top', getCss($min_btn, 'top'));
                $min_btn.data('drag', false);
            });

            $outbox.append($hour_line);
            $outbox.append($min_line);


            var $btn_line = $('<div class="zy-timer-btn"><button class="zy-timer-ok" type="button">确定</button><button class="zy-timer-clear" type="button">清除</button></div>');
            var $btn_ok = $btn_line.find('button.zy-timer-ok');
            var $clear_ok = $btn_line.find('button.zy-timer-clear');
            $btn_ok.off('click').on('click', function () {
                showTime();
                $outbox.stop().fadeOut('fast');
            });
            $clear_ok.off('click').on('click', function () {
                showTime(true);
                $outbox.stop().fadeOut('fast');
            });
            $outbox.append($btn_line);

            self.element.after($outbox);

            self.element.off('click').on('click', function () {
                $outbox.stop().fadeIn('fast');
            });

            self.element.off('blur').on('blur', function () {
                //$outbox.stop().fadeOut('fast');
            });

            return self;
        }
    };
    $.fn.timePicker = function (options) {
        var picker = new T(this, options);
        return picker.init();
    }
})(jQuery);


/**
 * select3 通用下拉框
 * 调用形式: JQ.select3()
 * 基本功能: 下拉选择、模糊搜索
 * 使用情景: 需要下拉选项处
 */
;(function ($) {
    function SELECT(element, options) {
        /**
         * select3 JS对象 在生命周期内有五项属性值
         * 1 - value : 自身 value ID值
         * 2 - text : 自身 text NAME值
         * 3 - mile : 自身 mile 附加属性值(绝对距离)
         * 4 - vary : 自身 vary 验证属性值
         * 5 - title: 自身 title 标题值
         * 3 - element : JQ 对象,在这里是指调用 select3 的 blockquote
         * 4 - defaults : 默认配置项
         * 5 - settings : 传入 options 后被重置的配置项
         */
        this.element = element;
        this.length = 0;
        this.defaults = {
            id: '',                         // ID
            index: '',                      // 索引
            height: 200,                    // 默认高度
            allowClear: true,               // 允许清除值(text & value),默认为true
            clearDrop: true,                // 清除值操作是否显示下拉框,默认为true
            clearAction: true,              // 清除操作后是否触发改变值事件,默认为true
            scrollLen: 5,                   // 出现垂直滚动条的数据长度
            data: [],                       // 下拉数据 为[{id:1,text:'1'},...]
            search: true,                   // 默认关闭搜索true
            server: false,                  // 是否启用服务器搜索,默认为false
            serverData: false,              // 服务器返回数据,默认为false
            usable: true,                   // 是否可用,默认为true
            title: '',                      // 标题(可用于出错提示)
            mileage: false,                 // 是否需要绝对距离,默认为false
            param: {},                      // 查询参数
            serverPath: '',                 // 服务器URL,默认为桩或阀室
            mileType: 'int',                // 绝对距离类型(整数int,小数float)
            pigType: 'normal'               // 清管的起点查询需要传入参数(不是清管的时候为normal,是清管的时候为pig)
        };
        this.settings = $.extend({}, this.defaults, options);
    }

    SELECT.prototype = {
        /**
         * fill函数 在 select3 初始化后只填充下拉框
         * 注意:多数情景下供内部使用
         * @param d
         * @returns {SELECT}
         */
        fill: function (d, v) {
            var self = this;
            var $span = self.element.find('span.bk-input-span');
            var $input = self.element.find('input.bk-input');
            var $abbr = self.element.find('abbr.bk-abbr');
            var $ul = self.element.find('ul.bk-ul');
            $ul.empty();
            $span.removeClass('error');
            if (d.length > 0) {
                var len = d.length;
                if (len > self.settings.scrollLen) {
                    $ul.css({'height': self.settings.height, 'overflow-y': 'scroll'});
                } else {
                    $ul.removeAttr('style');
                }
                for (var i = 0; i < len; i++) {
                    var $li_0 = $('<li></li>');
                    $li_0.text(d[i]['text']).attr('data-value', d[i]['id']).attr('data-mile', d[i]['mile']);
                    $ul.append($li_0);
                }
                if (v) {
                    self.seter({'vary': d});
                }
            } else {
                if (self.settings.server && v) {
                    if (self.settings.serverData instanceof Function) {
                        var data = self.settings.serverData(v);
                        if (data.length > 0) {
                            var lens = data.length;
                            if (lens > self.settings.scrollLen) {
                                $ul.css({'height': self.settings.height, 'overflow-y': 'scroll'});
                            } else {
                                $ul.removeAttr('style');
                            }
                            for (var j = 0; j < lens; j++) {
                                var $li_1 = $('<li></li>');
                                $li_1.text(data[j]['text']).attr('data-value', data[j]['id']).attr('data-mile', data[j]['mile']);
                                $ul.append($li_1);
                            }
                        } else {
                            $input.attr('title', '').attr('data-value', '').attr('data-mile', '');
                            $abbr.text('').attr('title', '').attr('data-value', '').attr('data-mile', '');
                            self.seter({
                                'value': '',
                                'text': '',
                                'mile': '',
                                'vary': '',
                                'store': ''
                            });
                            $ul.empty().removeAttr('style').append('<li data-value="">未找到结果</li>');
                        }
                    } else {
                        var param = {};
                        param.signName = v;
                        for (var k in self.settings.param) {
                            if (typeof(self.settings.param[k]) === 'object') {
                                param[k] = self.settings.param[k].val();
                            } else if (typeof(self.settings.param[k]) === 'string') {
                                param[k] = self.settings.param[k];
                            } else {
                                param[k] = '';
                            }
                        }
                        var url = self.settings.serverPath;
                        if (!url) {
                            if (self.settings.pigType == 'normal') {
                                url = DyyBase.url_sign();
                            } else if (self.settings.pigType == 'pig') {
                                url = DyyBase.url_sign() + '?targetType=valveRoomBall';
                            }
                        }
                        DyyBase.ajax(url, param, function (dataset) {
                            if (dataset.bool) {
                                var json = [];
                                if (self.settings.mileType === 'int') {
                                    json = DyyBase.getSelect(dataset);
                                } else if (self.settings.mileType === 'float') {
                                    json = DyyBase.getSelect(dataset, true);
                                }
                                self.add(json, v);
                            }
                        });
                    }
                } else {
                    $input.attr('title', '').attr('data-value', '').attr('data-mile', '');
                    $abbr.text('').attr('title', '').attr('data-value', '').attr('data-mile', '');
                    self.seter({
                        'value': '',
                        'text': '',
                        'mile': '',
                        'vary': ''
                    });
                    $ul.empty().removeAttr('style').append('<li data-value="">未找到结果</li>');
                }
            }
            return self;
        },

        /**
         * add函数 在 select3 初始化后只填充下拉框
         * 注意:多数情景下供外部使用
         * @param d
         * @returns {SELECT}
         */
        add: function (d, v) {
            var self = this;
            var $ul = self.element.find('ul.bk-ul');
            var $span = self.element.find('span.bk-input-span');
            var $input = self.element.find('input.bk-input');
            var $abbr = self.element.find('abbr.bk-abbr');
            var $disabled = self.element.find('input.bk-disabled');
            self.element.removeClass('disabled');
            $disabled.addClass('hidden');
            $input.attr('title', '').attr('data-value', '').attr('data-mile', '');
            $abbr.attr('title', '').attr('data-value', '').attr('data-mile', '');
            if (v === undefined) {
                $input.val('请选择').addClass('gray');
                $abbr.text('请选择').addClass('gray');
            }
            $ul.empty();
            $span.removeClass('error');
            self.seter({
                'value': '',
                'text': '',
                'mile': ''
            });
            if (d && d.length > 0) {
                self.seter({'store': d});
                var len = d.length;
                if (len > self.settings.scrollLen) {
                    $ul.css({'height': self.settings.height, 'overflow-y': 'scroll'});
                } else {
                    $ul.removeAttr('style');
                }
                for (var i = 0; i < len; i++) {
                    var $li = $('<li></li>');
                    $li.text(d[i]['text']).attr('data-value', d[i]['id']).attr('data-mile', d[i]['mile']);
                    $ul.append($li);
                }
            } else {
                $ul.removeAttr('style');
                $ul.append('<li data-value="">未找到结果</li>');
            }
            return self;
        },

        /**
         * asset函数 在 select3 初始化后 填充下拉框并设置初始值
         * 初始值为 data[0]
         * @param d
         * @returns {SELECT}
         */
        asset: function (d) {
            var self = this;
            var $ul = self.element.find('ul.bk-ul');
            var $span = self.element.find('span.bk-input-span');
            var $abbr = self.element.find('abbr.bk-abbr');
            var $input = self.element.find('input.bk-input');
            var $disabled = self.element.find('input.bk-disabled');
            self.element.removeClass('disabled');
            $disabled.addClass('hidden');
            $ul.empty();
            $span.removeClass('error');
            if (d && d.length > 0) {
                self.seter({'store': d});
                var len = d.length;
                if (len > self.settings.scrollLen) {
                    $ul.css({'height': self.settings.height, 'overflow-y': 'scroll'});
                }
                for (var i = 0; i < len; i++) {
                    if (i == 0) {
                        $input.val(d[i]['text']).attr('title', d[i]['text']).attr('data-value', d[i]['id']).attr('data-mile', d[i]['mile']).removeClass('gray');
                        $abbr.text(d[i]['text']).attr('title', d[i]['text']).attr('data-value', d[i]['id']).attr('data-mile', d[i]['mile']).removeClass('gray');
                        self.seter({
                            'value': d[i]['id'],
                            'text': d[i]['text'],
                            'mile': d[i]['mile'],
                            'vary': [{id: d[i]['id'], text: d[i]['text'], mile: d[i]['mile']}]
                        });
                    }
                    var $li = $('<li></li>');
                    $li.text(d[i]['text']).attr('data-value', d[i]['id']).attr('data-mile', d[i]['mile']);
                    if (i == 0) {
                        $li.addClass('active');
                    }
                    $ul.append($li);
                }
            } else {
                $ul.removeAttr('style');
                $input.val('请选择').attr('title', '').attr('data-value', '').attr('data-mile', '').addClass('gray');
                $abbr.text('请选择').attr('title', '').attr('data-value', '').attr('data-mile', '').addClass('gray');
                self.seter({
                    'value': '',
                    'text': '',
                    'mile': '',
                    'vary': '',
                    'store': ''
                });
                $ul.append('<li data-value="">未找到结果</li>');
            }
            return self;
        },

        /**
         * fit函数 在 select3 初始化后 设置一个匹配值
         * 比如在编辑的时候使用有奇效
         * @param v
         * @returns {SELECT}
         */
        fit: function (v) {
            var self = this;
            if (DyyBase.notEmpty(v)) {
                var $li = self.element.find('li');
                var $input = self.element.find('input.bk-input');
                var $abbr = self.element.find('abbr.bk-abbr');
                var $disabled = self.element.find('input.bk-disabled');
                self.element.removeClass('disabled');
                $disabled.addClass('hidden');
                if ($li.length > 0) {
                    $li.removeClass('active');
                    $li.each(function () {
                        var $this = $(this);
                        if ($this.attr('data-value') == v) {
                            $this.addClass('active');
                            var value = $this.attr('data-value');
                            var mile = $this.attr('data-mile');
                            var text = $this.text();
                            $input.val(text).attr('title', text).attr('data-value', value).attr('data-mile', mile).removeClass('gray');
                            $abbr.text(text).attr('title', text).attr('data-value', value).attr('data-mile', mile).removeClass('gray');
                            self.seter({
                                'value': value,
                                'text': text,
                                'mile': mile,
                                'vary': [{id: value, text: text, mile: mile}]
                            });
                        }
                    });
                }
            }
            return self;
        },

        /**
         * val函数 在 select3 初始化后 获取自身值 value
         */
        val: function (t) {
            if (t == 'text') {
                return this.element.data('text');
            } else if (t == 'store') {
                return this.element.data('store');
            } else if (t == 'vary') {
                return this.element.data('vary');
            } else if (t == 'mile') {
                return this.element.data('mile');
            } else if (t == 'index') {
                return this.element.data('index');
            } else {
                return this.element.data('value');
            }
        },

        /**
         * reset函数 重置 select3 此方法将提供给 form 一个可重置的接口事件
         * 和那个扩展的 form reset 配合使用
         * @returns {SELECT}
         */
        reset: function () {
            var self = this;
            var $input = self.element.find('input.bk-input');
            var $abbr = self.element.find('abbr.bk-abbr');
            var $ul = self.element.find('ul.bk-ul');
            $input.val('请选择').attr('title', '').attr('data-value', '').attr('data-mile', '').addClass('gray');
            $abbr.text('请选择').attr('title', '').attr('data-value', '').attr('data-mile', '').addClass('gray');
            $ul.find('li').removeClass('active');
            self.seter({
                'value': '',
                'text': '',
                'mile': '',
                'vary': ''
            });
            return self;
        },

        /**
         * 显示(true)或隐藏(false)下拉框
         * 多数情况下内部使用 如 init 时
         * @param t
         * @returns {SELECT}
         */
        play: function (t) {
            var self = this;
            var $drop = self.element.find('span.bk-drop-span');
            var $span = self.element.find('span.bk-input-span');
            var $arrow_b = self.element.find('b.bk-b-arrow');
            var $arrow_i = self.element.find('i.bk-i-arrow');
            if (t === true) {
                $drop.addClass('open').removeClass('hidden');
                $span.addClass('open');
                $arrow_b.addClass('open');
                $arrow_i.addClass('open');
            } else if (t === false) {
                $drop.addClass('hidden').removeClass('open');
                $span.removeClass('open');
                $arrow_b.removeClass('open');
                $arrow_i.removeClass('open');
            }
            return self;
        },

        /**
         * 设置 element 上的 data
         * 多数情况下内部使用 如 init 时
         * 此函数常用来设置如下值
         * 1.value 2.text 3.mile 4.store 5.vary 6.title 7.holder
         * @param o
         * @returns {SELECT}
         */
        seter: function (o) {
            var self = this;
            for (var i in o) {
                self.element.data(i, o[i]);
            }
            return self;
        },

        /**
         * 获取 element 上的 data
         * 多数情况下内部使用 如 init 时
         * 此函数常用来获取如下值
         * 1.value 2.text 3.mile 4.store 5.vary 6.title 7.holder
         * @param s
         * @returns {DATA}
         */
        geter: function (s) {
            var self = this;
            var data = self.element.data(s) ? self.element.data(s) : '';
            return data;
        },

        /**
         * 设置 select3 不可用
         * @param t
         * @returns {SELECT}
         */
        disable: function () {
            var self = this;
            self.element.addClass('disabled');
            var $disabled = '<input type="text" disabled="disabled" class="bk-disabled" title="不可用" value="">';
            var exist = self.element.find('input.bk-disabled');
            self.element.find('input.bk-input').attr('disabled', 'disabled');
            if (exist.length == 0) {
                self.element.append($disabled);
            }
            return self;
        },

        /**
         * 当 select3 初始化后并且拥有 serverPath 配置项时可使用此函数
         * 此函数为临时补丁上去 不推荐使用
         * 这里用到了 DyyBase 这种依赖关系不好
         */
        reload: function () {
            var self = this;
            var server = self.settings.serverPath;
            if (server) {
                DyyBase.ajax(server, self.param, function (dataset) {
                    if (dataset.bool) {
                        var json = DyyBase.getSelect(dataset);
                        self.add(json);
                    }
                });
            }
        },

        /**
         * select3 初始化 可被多次初始化
         * 完美
         * @returns {SELECT}
         */
        init: function () {
            var self = this;
            if (self.element.length > 0) {
                self.length = self.element.length;
                if($.trim(self.settings.id) != ''){
                    self.element.attr('id', self.settings.id);
                    self.element.attr('data-id', self.settings.id);
                }
                if($.trim(self.settings.index) != ''){
                    self.element.data('index', self.settings.index);
                    self.element.attr('data-index', self.settings.index);
                }
            } else {
                return self;
            }
            // exist dom data
            var ex_value = self.geter('value');
            var ex_text = self.geter('text');
            var ex_mile = self.geter('mile');
            var ex_store = self.geter('store');
            var ex_vary = self.geter('vary');
            var ex_title = self.geter('title');
            var ex_holder = self.geter('holder');

            // exist html
            var ex_html = $.trim(self.element.html());
            // exist abbr
            var ex_abbr = '<abbr></abbr>';

            // inner
            var inner = '<span class="bk-input-span"><abbr class="bk-abbr gray" title="" data-value="">请选择</abbr><input class="bk-input gray hidden" type="text" title="" value="请选择" data-value=""><i class="bk-i-clear hidden">×</i><i class="bk-i-arrow"><b class="bk-b-arrow"></b></i></span><span class="bk-drop-span hidden"><ul class="bk-ul"><li data-value="">未找到结果</li></ul></span><input type="text" value="" title="不可用" class="bk-disabled hidden" disabled="disabled">';

            // create
            if (ex_html) {
                if (ex_html == ex_abbr) {
                    if (!ex_holder) {
                        self.element.empty().append(inner);
                        self.seter({'holder': true});
                    }
                }
            } else {
                self.element.append(inner);
            }

            // init
            var $span = self.element.find('span.bk-input-span');
            var $input = self.element.find('input.bk-input');
            var $abbr = self.element.find('abbr.bk-abbr');
            var $ul = self.element.find('ul.bk-ul');
            var $clear = self.element.find('i.bk-i-clear');
            var $disabled = self.element.find('input.bk-disabled');

            // disabled
            if (self.settings.usable) {
                self.element.removeClass('disabled');
                $disabled.addClass('hidden');
            } else {
                self.element.addClass('disabled');
                $disabled.removeClass('hidden');
            }

            // search
            if (self.settings.search) {
                $abbr.addClass('hidden');
                $input.removeClass('hidden');
                $input.select(function (event) {
                    event.stopPropagation();
                    return false;
                });
            } else {
                $abbr.removeClass('hidden');
                $input.addClass('hidden');
            }

            // init data
            if (!ex_value) {
                self.seter({'value': ''});
            }
            if (!ex_text) {
                self.seter({'text': ''});
            }
            if (!ex_mile) {
                self.seter({'mile': ''});
            }
            if (!ex_vary) {
                self.seter({'vary': ''});
            }
            if (ex_title) {
                if (self.settings.title) {
                    self.seter({'title': self.settings.title});
                } else {
                    self.seter({'title': ex_title});
                }
            } else {
                var dom_title = self.element.attr('title');
                self.element.attr('title', '');
                if (dom_title) {
                    self.seter({'title': dom_title});
                }
                if (self.settings.title) {
                    self.seter({'title': self.settings.title});
                }
            }

            // init store
            var store = [];
            if (ex_store) {
                if (self.settings.data.length > 0) {
                    store = self.settings.data;
                } else {
                    store = ex_store
                }
            } else {
                if (self.settings.data.length > 0) {
                    store = self.settings.data;
                } else {
                    var empty_li = '<li data-value="">未找到结果</li>';
                    var html_li = $ul.html();
                    var $lis = $ul.find('li');
                    if (html_li && html_li.length > 0 && html_li != empty_li && $lis.length > 0) {
                        var li_arr = [];
                        $lis.each(function () {
                            var $this = $(this);
                            var value = $this.attr('data-value');
                            var text = $this.text();
                            li_arr.push({id: value, text: text});
                        });
                        if (li_arr.length > 0) {
                            store = li_arr;
                        }
                    }
                }
            }

            // init li
            if (store.length > 0) {
                self.seter({'store': store});
                if (self.geter('holder')) {
                    // nothing
                } else {
                    $input.val(store[0]['text']).attr('title', store[0]['text']).attr('data-value', store[0]['id']).attr('data-mile', store[0]['mile']).removeClass('gray');
                    $abbr.text(store[0]['text']).attr('title', store[0]['text']).attr('data-value', store[0]['id']).attr('data-mile', store[0]['mile']).removeClass('gray');
                    self.seter({
                        'value': store[0]['id'],
                        'text': store[0]['text'],
                        'mile': store[0]['mile'],
                        'vary': [{id: store[0]['id'], text: store[0]['text'], mile: store[0]['mile']}]
                    });
                }
                var len = store.length;
                $ul.empty();
                for (var i = 0; i < len; i++) {
                    var $li = $('<li></li>');
                    $li.text(store[i]['text']).attr('data-value', store[i]['id']).attr('data-mile', store[i]['mile']);
                    $ul.append($li);
                }
                if (len > self.settings.scrollLen) {
                    $ul.css({'height': self.settings.height, 'overflow-y': 'scroll'});
                }
            }

            // clear
            if (self.settings.allowClear) {
                $clear.removeClass('hidden');
                $clear.off('click').on('click', function (event) {
                    if (!(self.element.hasClass('disabled'))) {
                        $input.val('请选择').attr('title', '').attr('data-value', '').attr('data-mile', '').addClass('gray');
                        $abbr.text('请选择').attr('title', '').attr('data-value', '').attr('data-mile', '').addClass('gray');
                        $ul.find('li').removeClass('active');
                        $span.removeClass('error');
                        var data = [];
                        if (self.geter('store').length > 0) {
                            data = self.geter('store');
                        } else if (self.settings.data.length > 0) {
                            data = self.settings.data;
                        }
                        self.fill(data);
                        self.seter({
                            'value': '',
                            'text': '',
                            'mile': '',
                            'vary': ''
                        });
                        if (self.settings.clearDrop) {
                            self.play(true);
                        }
                        if (self.settings.clearAction) {
                            self.element.trigger('select');
                        }
                    }
                    event.stopPropagation();
                    return false;
                });
            } else {
                $clear.addClass('hidden');
            }

            // click
            self.element.off('click').on('click', function (event) {
                if (!(self.element.hasClass('disabled'))) {
                    self.play(true);
                }
                event.stopPropagation();
                return false;
            });

            // mouseleave
            self.element.off('mouseleave').on('mouseleave', function (event) {
                if (!($input.is(':focus'))) {
                    self.play(false);
                }
                event.stopPropagation();
                return false;
            });

            // focus
            self.element.off('focus').on('focus', 'input.bk-input', function (event) {
                var $this = $(this);
                var text = $.trim($this.val());
                if (text == '请选择') {
                    $this.val('').removeClass('gray');
                }
                event.stopPropagation();
                return false;
            });

            // focusout
            self.element.off('focusout').on('focusout', 'input.bk-input', function (event) {
                var $this = $(this);
                var text = $.trim($this.val());
                var title = '';
                if (self.geter('title')) {
                    title = self.geter('title');
                }
                if (self.settings.title) {
                    title = self.settings.title;
                }
                if (text) {
                    if (text == '请选择') {
                        $this.val('请选择').addClass('gray');
                    } else {
                        var value = $this.attr('data-value');
                        var vary = self.geter('vary');
                        if (!value) {
                            $span.addClass('error');
                            $this.attr('title', '不存在此' + title);
                            self.element.trigger('select', ['']);
                        }
                        if (vary.length > 0) {
                            if (vary[0]['text'] == text) {
                                var v_text = vary[0]['text'];
                                var v_value = vary[0]['id'];
                                var v_mile = vary[0]['mile'];
                                $span.removeClass('error');
                                $input.attr('title', v_text).attr('data-value', v_value).attr('data-mile', v_mile);
                                $abbr.text(v_text).attr('title', v_text).attr('data-value', v_value).attr('data-mile', v_mile);
                                self.seter({
                                    'value': v_value,
                                    'text': v_text,
                                    'mile': v_mile
                                });
                                self.element.trigger('select', [v_value]);
                            } else {
                                $span.addClass('error');
                                if (title) {
                                    $this.attr('title', '不存在此' + title);
                                }
                            }
                        }
                    }
                } else {
                    $abbr.text('').attr('title', '').attr('data-value', '').attr('data-mile', '');
                    $this.val('请选择').addClass('gray').attr('title', '').attr('data-value', '').attr('data-mile', '');
                    self.seter({
                        'value': '',
                        'text': '',
                        'mile': ''
                    });
                    self.element.trigger('select', ['']);
                }

                self.play(false);

                event.stopPropagation();
                return false;
            });

            // keyup
            self.element.off('keyup').on('keyup', 'input.bk-input', function (event) {
                var $this = $(this);
                var text = $.trim($this.val());
                var data = [];
                if (self.geter('store').length > 0) {
                    data = self.geter('store');
                } else if (self.settings.data.length > 0) {
                    data = self.settings.data;
                }
                if (text) {
                    var len = data.length;
                    var arr = [];
                    if (len > 0) {
                        var reg = new RegExp(text);
                        for (var i = 0; i < len; i++) {
                            if (reg.test(data[i]['text'])) {
                                arr.push({id: data[i]['id'], text: data[i]['text'], mile: data[i]['mile']});
                            }
                        }
                    }
                    self.fill(arr, text);
                } else {
                    self.fill(data);
                }
                event.stopPropagation();
                return false;
            });

            // paste
            self.element.off('paste').on('paste', 'input.bk-input', function () {
                var $this = $(this);

                function pt() {
                    var text = $.trim($this.val());
                    var data = [];
                    if (self.geter('store').length > 0) {
                        data = self.geter('store');
                    } else if (self.settings.data.length > 0) {
                        data = self.settings.data;
                    }
                    if (text) {
                        var len = data.length;
                        var arr = [];
                        if (len > 0) {
                            var reg = new RegExp(text);
                            for (var i = 0; i < len; i++) {
                                if (reg.test(data[i]['text'])) {
                                    arr.push({id: data[i]['id'], text: data[i]['text'], mile: data[i]['mile']});
                                }
                            }
                        }
                        self.fill(arr, text);
                    } else {
                        self.fill(data);
                    }
                    self.play(true);
                }

                window.setTimeout(pt, 4);
            });

            // mousedown
            self.element.off('mousedown').on('mousedown', 'li', function (event) {
                var $this = $(this);
                var value = $this.attr('data-value');
                var mile = $this.attr('data-mile');
                var text = $this.text();
                if (text && text != '未找到结果') {
                    $input.val(text).attr('title', text).attr('data-value', value).attr('data-mile', mile).removeClass('gray');
                    $abbr.text(text).attr('title', text).attr('data-value', value).attr('data-mile', mile).removeClass('gray');
                    self.seter({
                        'value': value,
                        'text': text,
                        'mile': mile,
                        'vary': [{id: value, text: text, mile: mile}]
                    });
                    if (self.settings.search) {
                        if ($input.is(':focus')) {
                            $input.blur();
                        } else {
                            self.element.trigger('select', [value, self.val('index')]);
                        }
                    } else {
                        self.element.trigger('select', [value, self.val('index')]);
                    }
                } else {
                    self.seter({
                        'value': '',
                        'text': '',
                        'mile': '',
                        'vary': ''
                    });
                }
                $span.removeClass('error');
                $ul.find('li').removeClass('active');
                $this.addClass('active');

                self.play(false);

                event.stopPropagation();
                return false;
            });

            // reset
            self.element.off('reset').on('reset', function (event) {
                self.reset();
                event.stopPropagation();
                return false;
            });

            // select
            self.element.off('select');

            return self;
        }
    };
    $.fn.select3 = function (options) {
        var select3 = new SELECT(this, options);
        return select3.init();
    }
})(jQuery);

